LoginSignup
1
1

More than 5 years have passed since last update.

FsUnitを使うとアセンブリの競合が出る場合の対処

Last updated at Posted at 2016-01-10

現象

Visual Studio 2015のF#プロジェクト(F#ランタイムバージョン:4.4.0.0)でNuGetからFsUnit(1.4.1)をインストールすると、一緒にFSharp.Core(3.1.2.5)とNUnit(2.6.4)もインストールされる。
このプロジェクトをビルドすると次のような警告が出た。

同じ依存アセンブリの異なるバージョン間で、解決できない競合が見つかりました。 これらの参照上の競合は、ログの詳細度が詳細に設定されている場合にビルドログにリストされます。

これは警告なのでビルドは成功するけれど、テストを実行しても次のようなエラーが発生してテストが失敗する。

System.MissingMethodException : メソッドが見つかりません: 'ParserResult`2<System.String,Microsoft.FSharp.Core.Unit> Test.test(System.String)'

解決方法

まずはNuGet パッケージマネージャーでFSharp.Coreのバージョンを4.0.0.1に更新する。

次にプロジェクトのApp.configを次のようにする(ない場合はVisual Studioの新しい項目の追加から"アプリケーション構成ファイル"を追加する)。
もし既に他の要素が定義されている場合は<dependentAssembly>の部分を追加すればよいと思う。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

これで警告が消えてテストも成功するようになった。

参考にしたサイト

FsUnit and Visual Studio 2013 “Could not load file or assembly ‘FSharp.Core, Version=4.0.0.0…” | Cyan By Fuchsia

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1