4

I have the following types defined in my an assembly:

type DatabaseDifferences = {missingTables: Table list}
type ComparisonResult = IsMatch | Differences of DatabaseDifferences

Then from my test assembly when I attempt to look at the length of the Table list on the DatabaseDifferences type I get the following error: System.MissingMethodExceptionMethod not found: 'Microsoft.FSharp.Collections.FSharpList``1<Table> DatabaseDifferences.get_missingTables()'.

Here is a cut down test that reproduces the issue:

let extractDifferences r =
    match r with
    | Differences(r') -> r'
    | _ -> failwith "expected databases to be different but they are a match"

[<Fact>]
let ``fail example``() =

    let d = Differences{missingTables = []} |> extractDifferences
    d.missingTables.Length |> should equal 0

If I declare the types in the same assembly as the tests then everything works, so for example this code passes (the Table type is still defined in the other assembly):

type diff = {missingTables: Table list}
type cr = IsMatch | Diffs of diff

let extract r =
    match r with
    | Diffs(r') -> r'
    | _ -> failwith "expected databases to be different but they are a match"

[<Fact>]
let ``fail example 2``() =

    let d = Diffs{missingTables = []} |> extract
    d.missingTables.Length |> should equal 0

I am using F# core version 4 and .Net version 4.6.2 in both assemblies

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Kevin Holditch
  • 5,165
  • 3
  • 19
  • 35
  • 4
    `MissingMethodException` is almost always caused by missing binding redirect for `FSharp.Core`. See for example http://stackoverflow.com/questions/33105382/why-do-i-get-a-missing-method-exception-runtime-when-creating-a-sqlclient-type – Tomas Petricek Dec 22 '16 at 12:50
  • Add FSharp.Core to your project through NuGet. Quite often (as in every time I open it) VS gets confused and uses the F# 3 version of FSharp.Core, which has an assembly version of .... 4.0. F# 4.0's version is 4.4.0. Using the NuGet package ensures that the proper files and redirects are used. What is the path of your FSharp.Core reference? – Panagiotis Kanavos Dec 22 '16 at 12:50
  • 1
    Thanks guys that was it. My test project was referencing FSharp Core V3 and my main assembly was referencing FSharp Core V4 – Kevin Holditch Dec 22 '16 at 13:45
  • I had a situation where integration tests (for protobuf serialization/deserialization) and a console program would work, but an FSI script would fail with missing method exceptions It turned out to be an older FSharp.Core version Nugetted into one of the Nuget dependencies of the system under test. Updated all to latest F# core, problem went away. Thanks! – Kit Jun 19 '18 at 13:29

0 Answers0