Why do I get a missing method exception runtime when creating a SqlClient type?

谁说胖子不能爱 提交于 2020-01-03 17:04:34

问题


I have the following code:

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)'.

回答1:


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.

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.)



来源:https://stackoverflow.com/questions/33105382/why-do-i-get-a-missing-method-exception-runtime-when-creating-a-sqlclient-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!