Can't load FSharp.Core version 4.0.0 in infer.

2019-04-10 16:48发布

问题:

I am trying Infer.Net (An F# Library for Probabilistic Programming) And running the examples in VS11 Beta lead to the error :

Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

If I open the dlls used the infer.net samples in Reflector, one, probcomp.dll, says it can not find automatically "FSharp.Core, Version=4.0.0.0"and that I need to select the location by hand.

Are the two things linked ? Is it possible that probcomp.dll has been compiled with a 'fixed path' reference and that now it is not the same on my machine ?

PS : of course fsharp projects from scratch are working fine..

PS2 : The dll under reference in visual studio do not show any sign that they are not found. And I can open them in the object browser.

UPDATE

The error happens tight at start of the program, there is no time to see anything. Yet, it happens INSIDE the program : If the following line is not called

let coinsD = inferExpr <@ coins @> 

Then the errors does not happen. With it, the following error is raised, in a different example Unsurprisingly, it is from the dll whose behaviour was strange in reflector.

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

The signature of the said function is quite strange in the object browser :

public static IDistribution<b>inferExpr<b>(**unknown-type e**)

YET, in reflector after I told him where to find Fsharp 4.0.0 upon opening the dll, it has the signature

public static IDistribution<b> inferExpr<b>(FSharpExpr<b> e);

This dll must have some kind of strange hard link dependencies, and reflector is smarter (or not..) than VS to figure it out.

To make a good from a bad, if you have any idea of what could have happened in this dll, this could be an occasion to learn.

回答1:

I'm able to run that example in VS11 targeting .NET 4.0 and using FSharp.Core 4.0.0.0. I encounter an error when targeting .NET 4.5 and changing FSharp.Core to 4.3.0.0 version.

So the problem is not hard link dependencies between dlls. Changing Target Framework in Project Properties to .NET 4.0 and carefully adding FSharp.Core 4.0.0.0 in Reference dialog (noticing there are various versions of FSharp.Core available) would solve the problem.

In your case, since F# 2.0 runtime is missing, installing it first before doing the above step.



回答2:

An app.config file with

<?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="4.0.0.0" newVersion="4.3.0.0"/>
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
</configuration>

will fix things right up.