Importance of pdb files
As per MSDN, “a program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program.” Please note that pdb files are not specific to C#, they are available for .Net languages as well
Now let’s take a look at few common debugging related issues
My yellow highlighting does not match the code line in length
When you are debugging a complex application, which is build on one machine and is being debugged on a different machine, you might find that the yellow highlighting is not matching the code line’s length. This is due to the mismatch between the code files and the deployed binaries.
To fix this issues, rebuild the whole set of projects, using the code files which you intend to use for the purpose of debugging. Now redeploy the newly built binaries along with the pdbs to the deploy location. If it involves GACing, copy the pdbs to GAC as well. Open a new instance of CLR debugger or visual studio on the machine where the binaries were deployed and open the code files, which you used to compile the deployed build, in it. Now hook up the debugger and put the break points, you will see that the length of yellow highlight is equal to the code line length
How do I debug a windows service?
- Open a new Debugger(CLR or studio).
- Click on the Tools menu, and click on “Attach to Process” menu item
- You will get a list of processes that are running on the local machine
- Select the process that matches the name of your windows service and click on attach.
Note that this is a general way of debugging any running process. Also note that you cannot debug an application whose type is not managed
How do I Debug a Windows Service which always fails before starting?
A windows Service will not fail to initialize unless there are unhandled exceptions in one the following three places
- Main function
- OnStart() method
What you can do is put a Debug.Assert(false); as the first line in your main function of the windows service and redeploy it. Now as you try and start the win service, you will get and empty Assert Window. Don’t dismiss it. Open up a debugger and hook up into the service. Put the break points at the suspect places and then dismiss the assert by ignoring it. The control will break at the breakpoint. Debug your service from here on
How do I debug an installer?
Debugging an installer is similar to debugging the windows service. Put the Debug.Assert where you want to start debugging and attach to the msiexec.exe process.
How do I debug an application hosted in IIS?
Hook up to aspnet_wp.exe in xp or w3wp.exe in Windows 2003 server. Haven’t taken a look at the process name under vista.