Debugging server side code in Visual Studio
- Updated on 11 Dec 2013
- 2 minutes to read
After writing your own code for Decisions , you will often want to debug this code. To do so follow the steps outlined below.
Build and deploy your code.
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.
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 Conditions...
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 break point will only catch if this condition is met.
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 ran. 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 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 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.
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.