F# 测试采用函数参数的函数时出现MissingMethodException

F# 测试采用函数参数的函数时出现MissingMethodException,f#,nunit,missingmethodexception,fsunit,F#,Nunit,Missingmethodexception,Fsunit,我正在使用FSUnit2.1(带有NUnit 3.2)为一个F#项目编写测试。下面是一个简单的模块: namespace Library1 module LibraryFunctions = let Execute f1 = f1() let Id x = x 以下是我的测试: namespace Tests open FsUnit open NUnit.Framework open Library1 [<TestFixture>] type Tests() =

我正在使用FSUnit2.1(带有NUnit 3.2)为一个F#项目编写测试。下面是一个简单的模块:

namespace Library1
module LibraryFunctions =
    let Execute f1 = f1()
    let Id x = x
以下是我的测试:

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
命名空间测试
开放式FSU
打开NUnit.Framework
开放图书馆1
[]
型式试验()=
[]
//通行证
成员x.`LibraryFunctions.Id应返回值``()=
LibraryFunctions.Id 42 |>应等于42
[]
//失败
成员x.``LibraryFunctions.Execute应返回函数`()=
设f()=42
LibraryFunctions.Execute f |>应等于42
第二次测试失败(在NCrunch和ReSharper中),并显示以下消息:

System.MissingMethodException:找不到方法:'!!0 Library1.LibraryFunctions.Execute(Microsoft.FSharp.Core.FSharpFunc`2')。


如果我将模块放在与测试相同的代码文件中进行测试(而不是放在单独的VS项目中),测试就会通过。我怀疑这是由于NUnit和F#/C#interop的一些问题造成的。如果是,如何解决?

这是FsUnit和其他项目的已知问题(请参阅和)

作为一种解决方法,您可以将其添加到app.config文件中:

<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>


注意:当FsUnit程序集更新时,您需要将
4.3.0.0
更新到您正在使用的
FSharp.Core
的任何版本。

您可以检查两个项目的F#(Core)版本吗?两个测试都通过了我的测试。在一个项目中,我有
Library1
,其中F#core:4.3.1.0,然后我有“Testes”“在另一个项目中,FsUnit:2.1、NUnit:3.2和F#Core:3.1.2.5特定版本:False。我正在使用VS 2015。我没有NCrunch和ReSharper。测试正在使用安装了NUnit VS适配器的测试资源管理器在VS中运行。@CaringDev
Library1
正在使用FSharp。Core 4.4.0.0、
Tests
正在使用特定版本为false的3.1.2.5。请尝试将它们设置为相同版本。这是版本不匹配时经常遇到的问题。我没有可用的IDE,但IIRC必须将程序集绑定重定向添加到配置文件中。谷歌为适当的设置。