使用Unquote断言时出现MissingMethodException

Ser*_*lov 5 f# nunit missingmethodexception f#-unquote

我试图用所享有与NUnit的为测试运行.测试用例取自" 入门",并在NUnit外部运行时按预期工作:

namespace FsTest.Tests

open NUnit.Framework
open Swensen.Unquote

[<TestFixture>]
module Example =

    [<Test>]
    let foo() = 
        test <@ (1+2)/3 = 1 @>
Run Code Online (Sandbox Code Playgroud)

在NUnit下我得到这个例外:

FsTest.Tests.Example.foo:System.MissingMethodException:找不到方法:'System.Tuple 2<Microsoft.FSharp.Collections.FSharpList1,Microsoft.FSharp.Quotations.FSharpExpr> Internal.reduceFullyAndGetLast(Microsoft.FSharp.Quotations.FSharpExpr)'.

我想知道上面的代码是否有任何问题以及如何使其工作.raise如果有帮助的话,Unquote 对我来说也是失败的.

Ste*_*sen 8

根据您的问题描述,我怀疑您需要使用FSharp.Core从版本4.0.0.0到版本4.3.0.0 的绑定重定向来配置您的NUnit项目,因为最新版本的Unquote是为.NET 4.0构建的,而您的测试项目是针对.NET的4.5.

有关详细信息,请参阅 Unquote问题.我相信你的配置看起来像

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity
          name="FSharp.Core"
          publicKeyToken="b03f5f7f11d50a3a"
          culture="neutral"/>
        <bindingRedirect
          oldVersion="2.0.0.0"
          newVersion="4.3.0.0"/>
        <bindingRedirect
          oldVersion="4.0.0.0"
          newVersion="4.3.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我不确定你需要把它放在NUnit项目的哪个位置,但可能在通过项目编辑器指定的配置文件中?

不幸的是,我没有安装VS2012,所以我在为你真正诊断这个问题的能力上有点瘫痪.