为什么在创建SqlClient类型时出现缺少的方法异常运行时? [英] Why do I get a missing method exception runtime when creating a SqlClient type?

查看:91
本文介绍了为什么在创建SqlClient类型时出现缺少的方法异常运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

open FSharp.Data

[<Literal>]
let connectionString = @"Data Source=(local)\SQLExpress;Integrated Security=SSPI;Database=SfagStage"

type InsertEnhet = SqlCommandProvider<"Sql\InsertEnhet.sql", connectionString>

let insertEnhet (enhet:Enhet) = 
    let cmd = new InsertEnhet() // <<--- This generates an error runtime
    cmd.Execute(enhet.Navn, enhet.Enhetsnummer, enhet.LEIKode, enhet.Kommune, DateTime.Now)

我创建命令的行是导致我认为缺少方法的原因.我认为重要的异常部分是:

The row where I create the command is what causing the missing method I think. The part that of the exception that I think matters is:

System.MissingMethodException: Method not found: 'Void FSharp.Data.ISqlCommand Implementation..ctor(FSharp.Data.Connection, Int32, System.String, Boolean, System.Data.SqlClient.SqlParameter[], FSharp.Data.ResultType, FSharp.Data.ResultRank, Microsoft.FSharp.Core.FSharpFunc`2, System.String)'.

推荐答案

当对FSharp.Core.dll没有正确的bindingRedirect时,可能会遇到这种异常.查看

This is the kind of exception that you may get when you don't have correct bindingRedirect for FSharp.Core.dll. Check out this article by Mark Seemann. In principle, I think that adding app.config with bindingRedirect to your application should solve the problem.

在使用较新版本的FSharp.Core的应用程序中使用针对较旧版本的FSharp.Core编译的库时,通常会发生这种情况. .NET运行时会加载FSharp.Core的新版本,但它不知道旧版本的类型(如FSharpFunc)应映射到新版本中的相应类型-因此您会获得MethodMissing,因为.NET认为FSharpFunc是与加载的类型不同的类型. (尽管使用类型提供程序会使事情变得更加复杂.)

This typically happens when using a library that is compiled against older version of FSharp.Core in an application that uses newer version of FSharp.Core. The .NET runtime loads the new version of FSharp.Core but it does not know that types from the older version (like FSharpFunc) should be mapped to corresponding types in the new version - and so you get MethodMissing, because .NET thinks that FSharpFunc is a different type than the loaded one. (Though things get a bit more complicated with type providers.)

这篇关于为什么在创建SqlClient类型时出现缺少的方法异常运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆