我有一个 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)'.
这是我在可移植类库中的 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>
最佳答案
MissingMethodException 就是这个意思(就签名而言)。
听起来您的测试代码没有引用 FSharp.Data
的版本您的可移植库正在使用的 DLL。asyncReadTextAtRuntime
的方法签名最近更改了,因此您必须在测试项目中引用最新版本。
请参阅此 GitHub 提交,该函数已更改为采用名为 formatName
的附加参数。 :
https://github.com/fsharp/FSharp.Data/commit/be3651f314b7a13b57a755a728287373adda775d#diff-a47e4306ce1338946e18435ee1e97c50R304
关于f# - 运行使用 FSharp.Data 的单元测试时出现 MissingMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23389752/