Table of Contents

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.

  1. In Visual Studio, open your solution.
  2. Go to Debug > Attach to Process... (or press Ctrl+Alt+P).
  3. In the "Available processes" list, search for dotnet.
  4. 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.
  5. 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.

  1. 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 Dependencies folder or in the AspNetCore project).
  2. 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.

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

  1. Add the code

    Insert the following line where you want the debugger to break:

    System.Diagnostics.Debugger.Launch();
    
  2. Rebuild and restart

    Rebuild your project and restart the server application.

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

See also