1
votes

I am trying to use the FSharp.Data library in a F# class library project (Not portable class. I am getting this error:

Test 'Test1' failed: OneTimeSetUp: System.MissingMethodException : Method not found: 'FSharp.Data.CsvFile FSharp.Data.CsvFile.Load(System.String, Microsoft.FSharp.Core.FSharpOption1<System.String>, Microsoft.FSharp.Core.FSharpOption1, Microsoft.FSharp.Core.FSharpOption1<Boolean>, Microsoft.FSharp.Core.FSharpOption1)'.

I googled the error and found a couple of the similar posts like this one

Using F# JsonProvider within a portable class library fails

but i am not in a portable class library just a normal class library. also i get similar error if i want to use the FSharp.Data in a F# unit test project.

Any advise will be appreciated.

FYI, I did install the the FSharp.Data in my Class library and test project which getting the error.

thanks

i have tried to target .net 4.5, 4.5.2 and F# 4.3.1 and 4.4 with FSharp.Data version 2.0.14 to 2.3.2 i have no luck with any of the combo.

1
All the problems I've seen with MissingMethodException have the same cause: assembly version conflicts. The solution is to add an assembly binding redirect in an App.config file. This is bound to be a duplicate, e.g. of stackoverflow.com/q/23389752/126014 There are 31 results here on Stack Overflow. - Mark Seemann
Hi Mark, the link has the solution as "Apparently, FSharp.Data does not support PCL libraries using profile 7. After changing my PCL project profile to 47 everything works as expected". But I am not writing a Portable Class (rather a normal class library). I can call the offending F# Class library (uses the FSharp.Data) from a console program with no error. I discovered this problem only during my Unit test of this F# Class library. Obviously my Test project is a Class library project. if it is the assembly is the issue, i would have got the same error in the console app. - casbby
Have you tried looking at one of the other 31 posts here? E.g. this one? stackoverflow.com/q/13846561/126014 - Mark Seemann
@MarkSeemann even when you manually set a reference to FSharp.Core 4.4.0, Visual Studio's test runner may pick up 4.3. I've been fighting this for the whole week. In the end I replaced references in my library and test projects with the FSharp.Core nuget package. Before that, the test runner wouldn't even find the tests - Panagiotis Kanavos
@casby in my case, I had to remove all manual references to FSharp.Core and use the FSharp.Core nuget package to ensure Visual Studio's test runner didn't load 4.3 (which is F# 3). Also check for missing redirects in your console app's app.config. - Panagiotis Kanavos

1 Answers

0
votes

Thanks to Mark and Panagiotis. I am able to resolve this missing method problem with binding redirection. For those having similar issue, I did the followings:

  1. add a new App.Config file to the test project.
  2. rename the config file to whateverAssemblyName.dll.config
  3. add the following lines (based on your F# version) to the config file:

       <runtime>
        <legacyUnhandledExceptionPolicy enabled="true" />
        <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>
    
  4. make sure the config file is exported to when newer

I have to use TestDriven/test with nunit to launch the nunit window as the VS test explorer still can't discover the test case.