Debugging a type provider can be difficult because it is a program run at compile-time and editing-time in host compilation tools including
fsc.exe
, devenv.exe
and FsAutoComplete.exe
.
This articule discusses some techniques you can use to debug a type provider when it is run inside these different tools.
To debug a use of a type provider inside the dotnet
toolchain, you should first isolate a precise invocation of the dotnet
tool used in compilation.
Capture output of dotnet build -v:n
in args.txt
and trim out the rubbish leaving just the command line arguments to the F# compiler, usually starting with -o:...
For example, on Windows:
|
Be careful to make sure Visual Studio debugging type is set to ".NET Core" (right click properties on dotnet and set debug type). Set first-catch exception handling (Ctrl-Alt-E, select all CLR exceptions) and set Just My Code off.
If your failures only happen in F# Interactive then use devenv /debugexe fsi.exe MyProj.fsproj
, or a simialr .NET SDK invocation.
This can be quite tricky. First try to unit-test the type-provider and debug command-line invocations thoroughly. If your failures only happen
in Visual Studio, then use devenv /debugexe devenv.exe MyProj.fsproj
, set debug type to ".NET Framework 4.0"
and launch F5.
To debug a use of a type provider inside the msbuild
toolchain (.NET Framework), you should first isolate a precise invocation of the dotnet
tool used in compilation.
Capture output of msbuild -v:n
in args.txt
and trim to leave the command line arguments to the F# compiler, usually starting with -o:...
For example, on Windows:
|
Set first-catch exception handling (Ctrl-Alt-E, select all CLR exceptions) and set Just My Code off.
For example, let's say you have this error in your test project:
|
Here your test project is referencing your provider project, and your type provider has a dependency on Newtonsoft.Json.dll
. To see what's going on, run
|
In the compilation of your test project you will see something like this:
|
The tool fsc.exe
is trying to load the type provider but a dependency is not found. As mentioned above, all dependencies must be packaged
alongside your design time component. For example, adding
|
will include the component and unblock you. However, you will need to be careful to make sure this component is laid down in the right place in your nuget package, see the instructions above for what the final layout of the nuget package should be.
TODO: give exact .fsproj/nuget instructions to get the dependency into the typeproviders\fsharp41\netstandard2.0
directory alongside the design-time component.