Use FSharp.Data in a Class library project or Test project

197 Views Asked by At

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

There are 1 best solutions below

0
On

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.