MissingMethodException when using Unquote asserts
Asked Answered
L

1

5

I'm trying to use unquote with NUnit as the test runner. The test case is taken from Getting Started and works as expected when run outside of NUnit:

namespace FsTest.Tests

open NUnit.Framework
open Swensen.Unquote

[<TestFixture>]
module Example =

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

Under NUnit I get this exception:

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)'.

I'd like to know if there's anything wrong with the code above and how I could make it work. Unquote's raise fail for me in the same way if that helps.

Lustring answered 12/12, 2012 at 18:50 Comment(2)
Can you please clarify what you mean by "run outside of NUnit" and "Under NUnit"? This issue looks very similar to https://mcmap.net/q/1174698/-unquote-what-am-i-missing/236255 except with the xUnit.net GUI test runner, where the OP learned he was referencing the wrong version of FSharp.Core.dllBottom
"run outside of NUnit" means using F# Interactive or a command line application from the same solution; "Under NUnit" means using a stock NUnit 2.6.2 GUI runner downloaded as a zip file. FScharp.Core.dll is referenced from the test assembly: <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">. The whole thing is VS 2012 targeting .NET 4.5.Lustring
B
8

Based on the description of your problem, I suspect you need to configure your NUnit project with an FSharp.Core binding redirect from version 4.0.0.0 to version 4.3.0.0 since the latest version of Unquote is built for .NET 4.0 and your test project targets .NET 4.5.

See this Unquote issue for details. I believe your configuration would look something like

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

I'm not sure exactly where you would need to put this for an NUnit project, but maybe in the config file specified through the Project Editor?

Unfortunately, I don't have VS2012 installed and so I am somewhat crippled in my ability to really diagnose this issue for you.

Bottom answered 12/12, 2012 at 19:49 Comment(1)
Great, that helped, thanks. For those who interested, NUnit uses <TestAssemblyName>.dll.config to configure test DLLs, so that's where you put these settings.Lustring

© 2022 - 2024 — McMap. All rights reserved.