问题
I have a Portable Library, for which the FSharp.Core
version is 3.7.4.0
. Installing (in the Unit Test project) FsUnit
installs, as a dependency, FSharp.Core
version 3.1.2.5
.
Due to this, using the portable library's functions in my Unit Test project, for example:
module StammaTests.PieceTests
open Stamma
open NUnit.Framework
open FsUnitTyped
[<Test>]
let ``Testing a Basic function`` () =
Piece.toChar Black King |> shouldEqual 'k'
yields error:
Result Message: System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=3.7.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Tried updating the FSharp.Core
version from NuGet to 4.0.0.1
(even checking both projects when updating) and now even something simple like :
[<Test>]
let ``Testing the test`` () = 1 |> shouldEqual 1
doesn't work, giving this similar error.
Result Message: System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
And the error for the first failing test doesn't change.
I feel like I am missing something painfully obvious, and I found several people with similar problems, but I don't understand what they did to solve it (they all seem to have solved it ..) For example this one.
Edit
Both projects are libraries and I do not have an app.config
file to add anything to.
回答1:
Add a binding redirect in your app.config
file to redirect all FSharp.Core
bindings to your desired version. For example, to use version 4.4.0, your app.config
file would look something like this:
<?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>
回答2:
I found a solution that actually worked here
Basically, adding an App.config
to the test project, and writing the following:
<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.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
It adds binding to both Fsharp.Core
and NUnit.Framework
, unlike the usual solutions where you only add a binding for Fsharp.Core
.
来源:https://stackoverflow.com/questions/39608983/fsunit-unable-to-test-portable-library-due-to-it-and-test-project-having-differ