1

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.

Community
  • 1
  • 1
casbby
  • 896
  • 7
  • 20
  • 4
    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 http://stackoverflow.com/q/23389752/126014 There are [31 results here on Stack Overflow](http://stackoverflow.com/search?q=%5bf%23%5d%20MissingMethodException). – Mark Seemann Aug 10 '16 at 05:07
  • 1
    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 Aug 10 '16 at 06:20
  • 2
    Have you tried looking at one of the other [31 posts](http://stackoverflow.com/search?q=%5bf%23%5d%20MissingMethodException) here? E.g. this one? http://stackoverflow.com/q/13846561/126014 – Mark Seemann Aug 10 '16 at 06:47
  • @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 Aug 10 '16 at 08:06
  • 3
    @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 Aug 10 '16 at 08:08

1 Answers1

0

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.

casbby
  • 896
  • 7
  • 20