Debugging server side code in Visual Studio

Last Updated: 12/05/2015 Introduced in Verision: 2.0
After writing your own code for Decisions, you’ll often want to debug this code. To do so follow the steps outlined below
Build and deploy your code on the same machine.
Run Visual Studio as Administrator


In Visual Studio, select Debug>Attach to Process


Select the process named DecisionsServiceHost.exe and click Attach


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

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

Additional Tips

Conditional Breakpoints
You can also set conditional break points. These are break points 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 break point 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 break point, right-click on it and click “Condition…”
You will now see a dialog where you can configure your condition. Write a Boolean statement just as you would in your code and click OK. Now your break point will only catch if this condition is met.
Debugging a Module Initialization
When starting ServiceHostManager the  Initialize() method of the module is run and thus any code in that method. Because it is run very soon after SHM is started, it is nearly impossible to start the service and then flip back over to VS 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 which 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 VS 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 how much time you need to attach your debugger.
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.

Additional Resources