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

标签 f# f#-data missingmethodexception

我有一个 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/

相关文章:

f# - Xamarin.Forms 是否支持 F#?

authentication - 如何在 JsonProvider 中对请求使用 HTTP 基本身份验证并在没有示例文件的情况下推断类型?

f# - 如何将 app.config 用于带有 FSharp.Data.TypeProviders 的数据库连接字符串?

grails - 为什么我不能捕获 Groovy 的 MissingMethodException?

wpf - 在我的 x64 笔记本电脑上将平台目标设置为 x86 会阻止某些 WPF 类型正确加载

F# ((*)2) 和 ((<<<)1) 行为不同

exception-handling - 如何在 F# 任务计算表达式中的每个步骤上实现非嵌套异常处理?

visual-studio-2012 - 系统丢失方法异常 : Method not found: 'Microsoft .FSharp.Core.FSharpFunc` 2

struct - 改变 F# [<Struct>] 记录

f# - 如何查看程序集中的类型提供程序