Getting F# Core method not found with or without assembly redirect. What else can I do?

Viewed 185

I have a library that uses FParsec as a NuGet package. A separate C# project that references this library keeps throwing an error:

System.MissingMethodException: 'Method not found: 'ParserResult`2<!!0,Microsoft.FSharp.Core.Unit> FParsec.CharParsers.run(Microsoft.FSharp.Core.FSharpFunc`2<FParsec.CharStream`1<Microsoft.FSharp.Core.Unit>,FParsec.Reply`1<!!0>>, System.String)'.'

The C# project targets .Net 4.6.1, whereas the library that uses FParsec target 4.5. N.B. I still run into the same issue, even when this library target 4.6.1.

Auto-generate binding results is on. Moreover, I've tried to manually set the binding redirects, e.g.,

<dependentAssembly>
    <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.6.2.0" newVersion="4.6.2.0" />
  </dependentAssembly>

I expected the auto-generate bindings option to handle this correctly.

1 Answers

It looks like you ran into the issue reported by me to the F# team here: https://github.com/dotnet/fsharp/issues/7718.

In summary, FParsec was compiled against an FSharp.Core version (version 4.4.0.0) that, when targeting a newer version of FSharp.Core in the rest of your project, or when using a bindingRedirect as you showed, will exhibit this error.

One resolution is to downgrade everything to an older version of FSharp.Core (namely the same as FParsec was compiled with). A better resolution is to download the FParsec source and compile it against a newer version of FSharp.Core. To do this:

  • Download the sources of FParsec from Github
  • Open your own solution, or an empty solution
  • From directory Build\VS11, add "existing project" FParsec.csproj and FParsecCS.csproj
  • Remove the FSharp.Core reference in FParsec by hand from the csproj file (the editor won't allow it). Remove it from FParsecCS.
  • Add any version (I tested 4.3.4 and higher) of FSharp.Core from NuGet to both FParsec and FParsecCS projects
  • Recompile
  • Reference the new binaries (or the new projects) from your project

The exception will now be gone.

Related