Sharepoint debugging isn’t fully automated. So you should really know how to debug and diagnose your assemblies in any given situation.
1. Attaching to the process
It only applies to a debugging environnement.
This is the one that everybody knows (or should at least). You deploy your DLL in the GAC, restart your application pool, access your sharepoint web application in order to load the application pool and the DLL and then attach to the right w3wp.exe process (or every w3wp.exe process if you don’t really know which one to choose).
2. Displaying where the exception happens
It should be used everywhere.
Just after deploying your DLL into the GAC, you should deploy the PDB file with it. In your exception management code, you have the exact line where the exception was thrown. Wether your users report it (with the exact line number), you see it in the logs or you have an automatic reporting system, the point is : You will know exactly where it fails.
If you have a WSP deployment method, you will have :
rem This WSP File contains the MyCorp.MyApp.MyLib library with the 0x123456789 public key token stsadm -o addsolution -filename %WSPFILE%
If you have a DLL deployment method, you will have :
gacutil /if GAC\MyCorp.MyApp.MyLib.dll
Either way, you need to add the PDB with this command :
subst X: c:\windows\assembly\gac_msil copy GAC\MyCorp.MyApp.MyLib.pdb X:\MyCorp.MyApp.MyLib\126.96.36.199_123456789\
If you’re not willing to give away your PDB file (it contains you complete code source and consumes space), you can find out where you app exactly failed just from the offset of the stacktrace reported by Sharepoint (with the CustomError=“Off” and StackTrace=“true” in the web.config). Some people explain how to do it here. Answer “3” allows you to get the IL offset like ASP.Net does in its (non customized) error page.
3. Launching the debugger from the code
This is very useful for features deactivation/uninstallation/installation/activation code.
You just have to add this line when you want to ask the debugger to attach to the assembly.
4. Other options
This article focuses on hardcore problems : Problems that occur inside sharepoint or weird problem that only appear on your production servers.
WinDBG method seems a little bit overkill to me. Mostly because you still can’t analyze the state of the local variables with our current tools (but I hope it will be made available in a short future).