System.MissingMethodException when using certain methods from FSharp PowerPack and compiling to a Class Library
Asked Answered
S

2

8

So I'm just getting started with F#, and I'm encountering a very weird issue where I get a System.MissingMethodException thrown when using certain methods from the FSharp PowerPack.

This does not happen for all methods in the same module. It also does not happen if I compile my assembly as an Application instead of a class library.

Reproduction steps:

  1. Create 2 assemblies, one Class Library and one Application.
  2. Add nunit.framework and the FSharp.PowerPack DLLs as references to both assemblies.
  3. Create the following test fixture in each assembly.

    open NUnit.Framework
    
    [<TestFixture>]
    type Tests() = class
    
        [<Test>]
        member self.OfSeq() =
            // Will always succeed
            Matrix.Generic.ofSeq [[1]] |> ignore
    
        [<Test>]
        member self.OfList() =
            // Will fail under certain conditions with a System.MissingMethodException
            Matrix.Generic.ofList [[1]] |> ignore
    end
    
  4. Compile both assemblies.
  5. Open each assembly in NUnit and run all the tests.

When I do this the Application runs just fine (all tests pass), but the Class Library fails with the following exception:

System.MissingMethodException : Method not found: 'Microsoft.FSharp.Math.Matrix`1<!!0> Generic.ofList(Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Collections.FSharpList`1<!!0>>)'.
   at Temp2.Tests.OfList()

What is going on here?

Another method that produces the issue is matrix.PermuteColumns.

Additional Info:

  • I'm compiling both assemblies for .NET 4.5
  • I'm compiling using Visual Studio 2012 RC
  • I'm using NUnit version 2.5.10.11092
  • I'm using FSharp PowerPack version 2.1.3.1 (though the DLL properties state that it's 2.0.0)

Let me know if there's additional information that would be of use.

Stairhead answered 10/8, 2012 at 18:9 Comment(1)
I believe the F# Powerpack DLLs are only compiled for .NET 2.0; if you want them to run 'natively' under .NET 4.0 or 4.5, you'll have to download the sources and build the assemblies yourself.Crib
E
3

I wonder if this is related to binding redirects. You may need to copy the app.config in the application project to the library project.

This sounds similar to a known issue that I'm currently writing a blog post about for the F# team blog (probably to appear in the next few weeks) regarding MSTest rather than NUnit. I would try copying the app.config into the library project, and if that doesn't work, then use the online template for unit testing here:

http://visualstudiogallery.msdn.microsoft.com/51ebe64a-899b-4959-8c24-b0148ed6b264

and additionally select 'TEST\Test Settings\Select Test Settings File' from the menu in VS, and point it at the 'MSTest.runsettings' file included in the unit test project template. I expect that one of those two tweaks will fix it in the MSTest case.

Eggett answered 10/8, 2012 at 18:20 Comment(3)
Copying the app.config fixed the issue. I'll keep an eye out for the blog post. Thanks for the help.Stairhead
same here, even though i did a machine wide redirect. there must be something else. those pesky issues are quite annoying.Necessitarianism
Different solution found when using VS2013 Preview and latest (V1.3) "F# MsTest Project": see my answer.Efficiency
E
12

(Answer for future reference since this Q was the first hit on searching.)

With Visual Studio 2013, with the "F# MSTest" online project template referenced by Brian, neither of Brian's suggestions helped (for a start the target of the testing is a library project without App.Config).

However I eventually found that the test project was set to use F#3 runtime (with FSharp.Core V4.3.0.0). Changing this to F# v3.1 (FSharp.Core V4.3.1.0) fixed the issue.

Efficiency answered 27/8, 2013 at 18:38 Comment(1)
This answer helped me - thanks for adding it to the question.Spirituality
E
3

I wonder if this is related to binding redirects. You may need to copy the app.config in the application project to the library project.

This sounds similar to a known issue that I'm currently writing a blog post about for the F# team blog (probably to appear in the next few weeks) regarding MSTest rather than NUnit. I would try copying the app.config into the library project, and if that doesn't work, then use the online template for unit testing here:

http://visualstudiogallery.msdn.microsoft.com/51ebe64a-899b-4959-8c24-b0148ed6b264

and additionally select 'TEST\Test Settings\Select Test Settings File' from the menu in VS, and point it at the 'MSTest.runsettings' file included in the unit test project template. I expect that one of those two tweaks will fix it in the MSTest case.

Eggett answered 10/8, 2012 at 18:20 Comment(3)
Copying the app.config fixed the issue. I'll keep an eye out for the blog post. Thanks for the help.Stairhead
same here, even though i did a machine wide redirect. there must be something else. those pesky issues are quite annoying.Necessitarianism
Different solution found when using VS2013 Preview and latest (V1.3) "F# MsTest Project": see my answer.Efficiency

© 2022 - 2024 — McMap. All rights reserved.