Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET runtime tries to load FSharp.Core 4.3.0 even if all projects reference 4.3.1

Tags:

c#

.net

f#

I've created a project in F# that targets F# 3.1 runtime (that is, FSharp.Core version 4.3.1). Then I've created a console C# application, added a project reference to my F# project, added a reference to FSharp.Core.dll 4.3.1.

Everything compiles without any errors or warnings, but the runtime throws this when I'm trying to use any type from F# project:

System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

Why does it searches for FSharp.Core 4.3.0 when all my projects reference 4.3.1? If I change all project references from 4.3.1 to 4.3.0 that everything will work fine, but what's up with version 4.3.1?

P.S. Both project target .NET 4.5.1. I am using Microsoft Visual Studio 2013

like image 900
RX_DID_RX Avatar asked Apr 09 '15 14:04

RX_DID_RX


1 Answers

This is the wild guess but based on the exception you get it's likely that you have other FSharp assemblies inside your project.

So the error indicates that one of the dependencies you're using requires FSharp.Core 4.3.0.0. Let's say your project references other FSharp dependencies like for example FSharp.Data 2.2.0.0. Even, if you have added an explicit reference in your own project to FSharp.Core 4.3.1.0 this won't work becasue FSharp.Data 2.2.0.0 was built against FSharp.Core 4.3.0.0. To fix that you need to add a bindingRedirect into your project configuration file app.config :

<?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.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This should fix the issue.

like image 138
Tomasz Jaskuλa Avatar answered Nov 16 '22 02:11

Tomasz Jaskuλa