首页 文章

运行使用FSharp.Data的单元测试时出现MissingMethodException

提问于
浏览
7

我有一个NUnit单元测试,它是用普通的F#库编写的,但它是针对可移植类库中的F#代码 .

当我运行此测试(在Visual Studio 2013中)时,我得到以下异常:

Result Message: System.MissingMethodException : Method not found:
 'Microsoft.FSharp.Control.FSharpAsync`1<System.IO.TextReader> FSharp.Data.Runtime.IO.asyncReadTextAtRuntime(System.Boolean, System.String, System.String, System.String, System.String)'.

这就是我在Portable Class Library中的app.config中所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<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-3.3.1.0" newVersion="3.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这就是我在普通F#库的app.config中所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<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.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

4 回答

  • 4

    MissingMethodException意味着(就签名而言) .

    听起来您的测试代码没有引用您的可移植库正在使用的 FSharp.Data DLL版本 .

    asyncReadTextAtRuntime 的方法签名最近已更改,因此您必须在测试项目中引用最新版本 .

    请参阅此GitHub提交,其中函数已更改为采用名为 formatName 的其他参数:

    https://github.com/fsharp/FSharp.Data/commit/be3651f314b7a13b57a755a728287373adda775d#diff-a47e4306ce1338946e18435ee1e97c50R304

  • 1

    显然,FSharp.Data不支持使用配置文件7的PCL库 . 将我的PCL项目配置文件更改为47后,一切都按预期工作 .

  • 0

    我有同样的问题,这与我所知道的PCL无关 . 在FSharp.Core的(C#)测试项目中添加显式绑定重定向使其消失(实际上我在Linqpad中也有同样的问题)

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    

    (C#中的测试项目本身没有直接的FSharp引用,除了它从它正在测试的F#项目继承的内容之外)

  • 4

    我将我的DLL版本更新为早期版本 .

    就我而言,我试图在FSharp.Data DLL中使用Type Providers .

    我将FSharp.Data更新为早期版本,错误消失了 .

相关问题