MissingMethodException when testing a function that takes a function parameter

I am using FsUnit 2.1 (with NUnit 3.2) to write tests for an F # project. Here is a simple module:

namespace Library1 module LibraryFunctions = let Execute f1 = f1() let Id x = x 

And here are my tests:

 namespace Tests open FsUnit open NUnit.Framework open Library1 [<TestFixture>] type Tests() = [<Test>] // Passes member x.``LibraryFunctions.Id should return the value``() = LibraryFunctions.Id 42 |> should equal 42 [<Test>] // Fails member x.``LibraryFunctions.Execute should return the result of the function``() = let f() = 42 LibraryFunctions.Execute f |> should equal 42 

The second test failed (in NCrunch and ReSharper) with the message:

System.MissingMethodException : Method not found: '!!0 Library1.LibraryFunctions.Execute(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,!!0>)'.

If I test the module in the same code file as the tests (and not in a separate VS project), the test passes. My suspicion is that this is due to some issues with NUnit and F # / C # interop. If so, how can this be resolved?

+4
source share
1 answer

This is a known issue with FsUnit and other projects (see here and here ).

As a workaround, you can add this to your app.config file:

 <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.0.0" newVersion="4.3.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 

Note: you will need update 4.3.0.0 for any version of FSharp.Core used by your FsUnit assembly when and when it will be updated.

+5
source

Source: https://habr.com/ru/post/1014346/


All Articles