5

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)'.
Guy Coder
25.1k8 gold badges78 silver badges144 bronze badges
asked Oct 13, 2015 at 14:31

1 Answer 1

5

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

answered Oct 13, 2015 at 14:40
3
  • 3
    I had the correct redirects, but I think it might have been due to an older version of FSharp.Core. Upgrading to the latest, 4.4.0.0, in nuget (instead of the one including in the VS project) fixed it for me. Commented Oct 13, 2015 at 14:42
  • 3
    Yeah, whenever I get odd error that makes no sense, I blame FSharp.Core :-) Commented Oct 13, 2015 at 14:44
  • Yes, the nuget worked perfectly. Its funny that the code will compile and runs fine from F# interactive, but dies at runtime when run from the actual application... makes you scratch your head for a moment.... Commented Apr 29, 2016 at 3:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.