FsUnit: Unable to test portable library due to it and test project having different F#.Core versions
Asked Answered
A

2

0

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.

Allin answered 21/9, 2016 at 6:30 Comment(0)
A
0

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.

Allin answered 21/9, 2016 at 11:34 Comment(2)
So, the implication seems to be that FSharp.Core has a reference to nunit.framework. Is that the case? I ask because it seems odd.Enwomb
I don't think that's the case. I only put here what worked for me.Allin
G
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>
Glaze answered 21/9, 2016 at 7:16 Comment(6)
Which project should I add this to?Allin
Just to be clear, both projects are libraries and I don't have an app.config file. I read this answer else where but as I don't have the file, I don't see how I can use it.Allin
Just add a new app.config file to your library projectGlaze
Couldn't get it work. I put <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="3.1.2.5" /> in my library , rebuit, and the same error. Different versions in the new versions didn't resolve it either.Allin
Well, you didn't say anything about a binding failure for nunit.frameworkGlaze
I shared what I knew.Allin
A
0

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.

Allin answered 21/9, 2016 at 11:34 Comment(2)
So, the implication seems to be that FSharp.Core has a reference to nunit.framework. Is that the case? I ask because it seems odd.Enwomb
I don't think that's the case. I only put here what worked for me.Allin

© 2022 - 2024 — McMap. All rights reserved.