Link to Snippet

Extract info from F# Compiler Service exceptions

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

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:

// Let's say that creating FsiEvaluator() fails with mysterious// error from the F# compiler service. We can catch the exception:lete=trynewFSharp.Literate.FsiEvaluator(); failwith"!"withe->e// Get the InnerException, which is the actual error from the compilerletae=e.InnerException// And get the values of the private fields!letopts=Reflection.BindingFlags.NonPublic|||Reflection.BindingFlags.Instance
[ forpinae.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..)