Skip to main content

Debugging

Generated code

To debug the code generated by Mapperly just set a breakpoint in the generated code and you are ready to go. Check here on how to inspect the generated code.

Unit tests

To debug the Mapperly in unit tests, set a breakpoint in the code of Mappery which you want to debug and run the tests in debug mode.

Integration tests

If your IDE supports the DebugRoslynComponent launch configuration command, you can set your breakpoints and debug the preconfigured IntegrationTests profile which will debug Mapperly in the context of the integration tests. JetBrains Rider and Visual Studio both support DebugRoslynComponent. Visual Studio requires the Roslyn SDK to be installed.

If your IDE does not support DebugRoslynComponent, debugging the integration tests requires some more effort. Mapperly uses a compile constant DEBUG_SOURCE_GENERATOR to determine whether to attach a debugger. If it is set, it tries to attach a debugger (it uses Debugger.Launch() on windows, on other operating systems it tries to launch JetBrains Rider) and waits for the connection of the debugger (for up to 30 seconds). If the automatic debugger attachment fails you can use these 30 seconds to attach the debugger manually (for Visual Studio see attach to running processes). You can use the DefineConstants dotnet build or csproj parameter to define the DEBUG_SOURCE_GENERATOR constant.

For the debugger attachment with JetBrains Rider to work correctly, Generate Shell Scripts needs to be enabled in the JetBrains ToolBox and the generated shell scripts need to be on the path (Mapperly calls rider attach-to-process {pid} {Mapperly-Sln-File}).