Home
Insert
Update snippet 'Extract info from F# Compiler Service exceptions'
Title
Description
When you get an exception from the F# Compiler Service, it usually does not print any useful information. But you can look at the private fields of the exception and get some more useful things out of it...
Source code
// Let's say that creating FsiEvaluator() fails with mysterious // error from the F# compiler service. We can catch the exception: let e = try new FSharp.Literate.FsiEvaluator(); failwith "!" with e -> e // Get the InnerException, which is the actual error from the compiler let ae = e.InnerException // And get the values of the private fields! let opts = Reflection.BindingFlags.NonPublic|||Reflection.BindingFlags.Instance [ for p in ae.GetType().GetFields(opts) -> p.Name, p.GetValue(ae) ] // This might give you some more useful information about the // error (e.g. for `FileNameNotResolved`, you actually get the file name..)
Tags
f# compiler service
exceptions
f# compiler service
exceptions
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update