MissingMethodException when trying to print a string in F#
Hi,
When I try to do a basic printfn
call in F#, I get a MissingMethodException
: Method not found: 'Void Microsoft.FSharp.Core.PrintfFormat`5..ctor(System.String)'.
The code to repro is simple:
printfn "%s" "Hi"
Any ideas on how to fix this?
Thanks,
Jon
Environment:
LINQPad 6.5.5 (x64)
Windows 10
VS 2019 16.4.1
❯ dotnet --list-sdks
1.1.8 [C:\Program Files\dotnet\sdk]
2.2.109 [C:\Program Files\dotnet\sdk]
2.2.402 [C:\Program Files\dotnet\sdk]
3.0.101 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
Comments
-
You're probably missing the reference assemblies. Click the exclamation mark in the toolbar to restore.
-
That fixed it. Thanks!
-
Hi, would you be able to point out what assemblies need to be referenced to fix this, exactly? I'm getting this exact error in some code I compile without LINQPad, running fsc.exe in my own application. Microsoft.FSharp.Core.PrintfFormat is, of course, defined in FSharp.Core.dll, which I'm already referencing.
-
You need the reference assemblies for the runtime that you're using (.NET 3.1 or .NET 5). If you have the SDK installed, they are located in %programfiles%\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0\ref\net5.0. If you don't have the SDK, you can download them from the Microsoft.NETCore.App.Ref NuGet package. I don't know whether fsc.exe has an option to help you with this.
Your other option is to use dotnet build - I believe this is the recommended solution outside Visual Studio and LINQPad.
-
Using the reference assemblies worked, thank you so much! It was a little trickier than that, because they are sometimes in %ProgramFiles% and sometimes a NuGet package for some reason (even though I do have the SDK).