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

7

我有一个在普通F#库中编写的NUnit单元测试,但是针对的是可移植类库中的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)'.

这是我在可移植类库的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的意思就是(在签名方面)确实缺少方法。

看起来你的测试代码没有引用与你的可移植库使用的 DLL版本相对应的内容。

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

请参阅此GitHub提交,其中该函数已更改以接受名为formatName的其他参数:

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


似乎并非如此,因为输出文件夹中的FSharp.Data DLL文件与被引用的文件完全相同。我将尝试使用不同的PCL配置文件,因为我使用的那个(新配置文件7)显然不被推荐:https://github.com/fsharp/FSharp.Data/issues/605 - Tiago

4

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


1
我遇到了同样的问题,但与我所知道的PCL无关。在(C#)测试项目中为FSharp.Core添加显式绑定重定向即可解决此问题(实际上,我在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#项目继承的内容。

0

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

在我的情况下,我试图在FSharp.Data DLL中使用类型提供程序。

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


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