4
votes

I upgraded Visual Studio from VS2017 to VS2019. I opened a solution with both C# and F# in it. A C# unit test project references a F# .dll project.

The solution compiles fine but at run time, I get the following message

System.IO.FileLoadException: 'Could not load file or assembly 'FSharp.Core, Version=4.6.2.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 inner exception is

Could not load file or assembly 'FSharp.Core, Version=4.6.0.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)

I have this in the unit tests app.config:

  <dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.6.2.0" newVersion="4.6.2.0" />
  </dependentAssembly>

and the unit test project has this in the packages.config

<package id="FSharp.Core" version="4.6.2" targetFramework="net461" />

Is there a missing reference I am not seeing?

Thanks

1
So what's in the project files? When I get this, I usually add a reference to FSharp.Core to the C# project. If you don't see a reference to it in the C# project, try adding. If you do see it, try removing and adding, and make sure it's 4.6.2.0 in csproj. Also check if your F# project really references 4.6.2.0 in fsproj. Also try without the redirect(s), because that fixed a similar case for me some days ago - don't know why.Bent Tranberg
Ok, I looked at my unit test project - an F# project with new project format. For some strange reason I am doing a bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.6.0.0" in spite of all projects in my solution using FSharp.Core 4.6.2.0. I'm using NUnit. Can you try changing the redirect to 4.6.0.0 in your unit test project and see if it helps? I suspect I got that same inner exception, and eventually arrived at this veird solution.Bent Tranberg

1 Answers

4
votes

Bent Tranberg was right

In the test project, I changed the binding redirect to

       <dependentAssembly>
         <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
         <bindingRedirect oldVersion="0.0.0.0-4.6.2.0" newVersion="4.6.0.0" />
       </dependentAssembly>

and it worked