14385

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

Question:

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:

<blockquote>

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)

</blockquote>

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.

<blockquote>

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)

</blockquote>

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 <a href="https://stackoverflow.com/questions/39206991/fsharp-core-could-not-load-file-or-assembly" rel="nofollow">this one</a>.

Edit

Both projects are libraries and I do not have an app.config file to add anything to.

Answer1:

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>

Answer2:

I found a solution that actually worked <a href="http://devcenter.wintellect.com/jwood/unit-testing-your-xamarin-forms-applications-with-f-and-fsunit" rel="nofollow">here</a>

Basically, adding an App.config to the <strong>test</strong> 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 <em>both</em> Fsharp.Core and NUnit.Framework, unlike the usual solutions where you only add a binding for Fsharp.Core.

Recommend

  • Transaction-like update of two documents using CouchDB
  • Google Charts backgroundColor not working with example code
  • Beego - Endpoint Testing
  • python dont capitalize after apostrophe [duplicate]
  • Use .net core DLL in Framework 4.6 project
  • Treating a string as an integer
  • handeling querying an item with a single quote in it
  • case statement logic [closed]
  • Multiple MySQL Table JOINs / id-to-value replacement / aliases
  • Excel - Search through a column to find if text matches and count string
  • VS2013 Build Definition 'Microsoft.TeamFoundation.Client.BasicAuthCredential' is not marke
  • TryParse double values
  • How to display Bitmap Image in image control on WPF using C#
  • Gephi's java default method not implemented in C# with an ikvm-from dll library
  • Assigning int value to string
  • Activation error occured while trying to get instance of type LogWriter, key “”
  • css font-size and line-height not matching the baseline
  • Graceful pod termination
  • insert a picture into database(sqlite) with java code. what should i do?
  • Getting error java.io.FileNotFoundException (log4j log file) at the time of publish project on cloud
  • Why can't I use non-integral types with switch [duplicate]
  • Translating C# to PowerShell in InterIMAP
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • Loading .coffee files via a view in Rails
  • Create DicomImage from scratch using Dcmtk
  • x64 applications using gdi+: what are the consequences on performance?
  • Deserializing XML into class C#
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • C# - Getting references of reference
  • coudnt use logback because of log4j
  • How does Linux kernel interrupt the application?
  • costura.fody for a dll that references another dll
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?