While debugging an F# application, I would like to be able to invoke an F# method from the VS2010 immediate window but it doesn’t seem to work. The problem appears to be that F# methods are actually FSharpFunc objects. I tried using the “Invoke” method but the interactive window doesn’t recognize it.
Share
The F# integration for Visual Studio doesn’t support F# expressions in immediate window (or watches), so the only option is to write C# code corresponding to the compiled representation that F# uses. I tried doing that and I’m having the same issue as you described – the
Invokemethod appears to be there (in Reflector), but Visual Studio doesn’t want to call it directly. I tried it using the following example:However, there are other ways to call the function. In this case, the actual code generated by the F# compiler is a call to
InvokeFastmethod. If you type the following to the immediate window, it works:It also appears that you can call the usual
Invokemethod usingdynamicfrom C# 4.0 (proving that the method is actually there!):This works only if you add reference to
Microsoft.CSharp.dll(and use some type defined in the assembly somewhere in your code – e.g. as an annotation – so that it gets loaded).