Debug server application
This article explains how to debug the backend code of your cluster (business assemblies, server methods, generated projects, etc.).
Attaching to the running process
As the server application must be started beforehand, you need to attach the debugger to the running process.
- In Visual Studio, open your solution.
- Go to Debug > Attach to Process... (or press
Ctrl+Alt+P). - In the "Available processes" list, search for
dotnet. - Identify the correct process by looking at the Command Line column. You should look for the DLL named
<RootNamespace>.AspNetCore.dll. It is easily recognizable as it contains a GUID in its path, which is due to the process recycling mechanism when modifications occur. - Select the process and click Attach.
Note
To debug a background process, you must attach to the <RootNamespace>.TaskRunner.dll process.
Setting breakpoints
Once attached, you can set breakpoints to pause execution at specific lines of code.
Open the file
Navigate to the file where you want to pause execution. You can set breakpoints in all the files that are part of your solution, including:
- Your business assembly (e.g., a validation rule, an event rule, or a server method).
- The business assemblies of dependent modules.
- The generated C# projects (located in the
Dependenciesfolder or in theAspNetCoreproject).
Toggle breakpoint
Click in the left margin next to the line of code, or place the cursor on the line and press F9. A red dot will appear.
Trigger the code
Perform the action in the frontend application (or via Swagger UI) that triggers the backend code. Visual Studio should hit the breakpoint and pause execution, allowing you to inspect variables and step through the code.
Using Debugger.Launch()
In some scenarios, it might be difficult to attach the debugger in time (e.g., during startup or early initialization). You can use the System.Diagnostics.Debugger.Launch() method to prompt for a debugger attachment directly from the code.
Add the code
Insert the following line where you want the debugger to break:
System.Diagnostics.Debugger.Launch();Rebuild and restart
Rebuild your project and restart the server application.
Select debugger
When the code execution reaches this line, a dialog will appear asking you to select a debugger. Choose your running Visual Studio instance.
Important
Remember to remove this line before deploying to production!