Debugging Server Side Code in Visual Studio
  • 26 Feb 2020
  • 2 Minutes to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Debugging Server Side Code in Visual Studio

  • Dark
    Light

Article summary

After writing your own code for Decisions, you will often want to debug this code. To do so follow the steps outlined below.

  1. Build and deploy your code.

  2. Run Visual Studio as Administrator

RunStudioAsAdmin.png

  1. In Visual Studio, select Debug > Attach to Process.
    AttachToProcess.png

  2. Select the process named DecisionsServiceHost.exe and click Attach.
    AttachToDecisions.png

If you have successfully attached the debugger you will see a Ready in the lower left.
SuccessfulAttachment.png

  1. Set a breakpoint on the line of code you are interested in. Do this by clicking in the grey bar left of your code.

SetBreakpoint.png

Additional Tips

Conditional Breakpoints
You can also set conditional breakpoints. These are breakpoints that will only catch when a certain condition is met. An example of where this would be helpful is when debugging a loop with many iterations. You can use the conditional breakpoint as a way of catching the debugger when your code gets to a certain record you are interested in instead of having to manually advance the debugger on each loop of the code. To do this, set a breakpoint, right-click on it and click Conditions...

BreakpointCondition-1.png

You will now see a dialog where you can configure your condition. Write a Boolean statement just as you would in your code. Now your breakpoint will only catch if this condition is met.

ConditionIsTrue-1.png

Debugging a Module Initialization
When starting Service Host Manager the  Initialize() method of the module is ran and thus any code in that method is also run. Since it runs very soon after SHM is started, it is nearly impossible to start the service and then flip back over to Visual Studio to attach the debugger before this method is run. So to enable debugging of this part of a module deploy, we have added a parameter that can be set on the SHM service which will delay the running of this  Initialize() method. Setting a delay gives you enough time to flip back over to Visual Studio and attach the debugger.

To set this delay, edit the properties of the Windows service named  Service Host Manager. In the Start parameters setting type /delay #### (where #### is the number of milliseconds you want to delay the running of the Initialize method). In the example shown below, we have set a 7-second delay. You can set this delay higher or lower depending on the amount of time you need to attach your debugger.

DelayShm.png

Stopping ServiceHostManagerWatcher

Stop the Windows Service named ServiceHostManagerWatcher. This service is designed to provide a more reliable production environment and will often get in the way when developing. It is designed to watch and start ServiceHostManager if it ever stops.


Was this article helpful?