使用Unquote断言时出现MissingMethodException异常

5

我正在尝试将unquote与NUnit一起作为测试运行器使用。测试用例取自入门指南,在NUnit之外运行时按预期工作:

namespace FsTest.Tests

open NUnit.Framework
open Swensen.Unquote

[<TestFixture>]
module Example =

    [<Test>]
    let foo() = 
        test <@ (1+2)/3 = 1 @>

在NUnit下,我遇到了这个异常:
FsTest.Tests.Example.foo: System.MissingMethodException : Method not found: 'System.Tuple2<Microsoft.FSharp.Collections.FSharpList1,Microsoft.FSharp.Quotations.FSharpExpr> Internal.reduceFullyAndGetLast(Microsoft.FSharp.Quotations.FSharpExpr)'.
我想知道上面的代码有什么问题,以及如何使它正常工作。如果有帮助的话,Unquote的raise也会失败。

请问您所说的“在 NUnit 之外运行”和“在 NUnit 下运行”是什么意思?这个问题看起来与 https://dev59.com/clzUa4cB1Zd3GeqP22Ub 非常相似,只不过使用了 xUnit.net GUI 测试运行器,其中 OP 发现他引用了错误版本的 FSharp.Core.dll。 - Stephen Swensen
“run outside of NUnit” 意味着使用 F# Interactive 或来自同一解决方案的命令行应用程序;“Under NUnit” 意味着使用从 zip 文件下载的标准 NUnit 2.6.2 GUI 运行器。测试程序集引用了 FScharp.Core.dll:<Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">。整个项目是在 VS 2012 中,目标为 .NET 4.5。 - Serge Belov
1个回答

8
根据您的问题描述,我怀疑您需要将NUnit项目配置为使用FSharp.Core绑定重定向从版本4.0.0.0到版本4.3.0.0,因为最新版本的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>

我不确定你需要将这个放在哪里,适用于NUnit项目,但可能是通过Project Editor指定的配置文件吗?
不幸的是,我没有安装VS2012,所以我在为你诊断这个问题方面有些受限。

1
太好了,这很有帮助,谢谢。对于那些感兴趣的人,NUnit使用<TestAssemblyName>.dll.config来配置测试DLL,所以这就是您放置这些设置的地方。 - Serge Belov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接