MissingMethodException when running a unit test that uses FSharp.Data
Asked Answered
E

4

7

I have a NUnit unit test that is written in a normal F# library but targets F# code in a Portable Class Library.

When I run this test (in Visual Studio 2013), I get the following exception:

Result Message: System.MissingMethodException : Method not found:
 'Microsoft.FSharp.Control.FSharpAsync`1<System.IO.TextReader> FSharp.Data.Runtime.IO.asyncReadTextAtRuntime(System.Boolean, System.String, System.String, System.String, System.String)'.

This is what I have in my app.config in the Portable Class Library:

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

This is what I have in the app.config of my normal F# library:

<?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>
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Excerpta answered 30/4, 2014 at 13:41 Comment(0)
E
4

Apparently, FSharp.Data does not support PCL libraries using profile 7. After changing my PCL project profile to 47 everything works as expected.

Excerpta answered 1/5, 2014 at 8:39 Comment(0)
L
4

The MissingMethodException means exactly that (in terms of signature).

It sounds like your test code doesn't have a reference to the version of FSharp.Data DLL that your portable library is using.

The method signature for asyncReadTextAtRuntime was changed very recently, so you must reference the latest version in your test project.

See this GitHub commit, where the function was altered to take an additional parameter called formatName:

https://github.com/fsharp/FSharp.Data/commit/be3651f314b7a13b57a755a728287373adda775d#diff-a47e4306ce1338946e18435ee1e97c50R304

Lavation answered 1/5, 2014 at 4:52 Comment(1)
That does not seem to be the case as the FSharp.Data DLL file in the output folder is exactly the same as the one being referenced. I will try using a different PCL profile as the one I was using (new profile 7) is apparently not recommended: github.com/fsharp/FSharp.Data/issues/605Excerpta
E
4

Apparently, FSharp.Data does not support PCL libraries using profile 7. After changing my PCL project profile to 47 everything works as expected.

Excerpta answered 1/5, 2014 at 8:39 Comment(0)
T
1

I had this same issue, and it was nothing to do with PCLs that I was aware. Adding an explicit binding redirect in the (C#) testing project for FSharp.Core made it go away (actually I had the same issue in Linqpad also)

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" />
  </dependentAssembly>
</assemblyBinding>

(The testing project in C# has no direct FSharp references itself, other than what it inherits from the F# projects it's testing)

Tenant answered 24/11, 2016 at 3:45 Comment(0)
M
0

I updated my version of the DLL to an earlier version.

In my case, I was attempting to use Type Providers in the FSharp.Data DLL.

I updated FSharp.Data to an earlier version and the error went away.

Myasthenia answered 19/2, 2017 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.