Debugging .NET with WinDbg and SOS

WinDbg is a command-based debugger for Windows that can sometimes help track down problems when Visual Studio gets in the way. SOS is a WinDbg extension which helps with .NET debugging.

Once WinDbg is installed, you should configure your symbol path (which is needed for clean stack traces). You can either set an environment variable for the symbols, or reset them every time you run WinDbg.

From environment variable:
_NT_SYMBOL_PATH=SRV*c:\websymbols*http://msdl.microsoft.com/download/symbols

From Windbg:
.sympath SRV*c:\websymbols*http://msdl.microsoft.com/download/symbols
.reload

c:\websymbols is the path where the PDB symbol files will be cached from the symbol server.

Articles About Using WinDbg/SOS

Jason Zander's SOS Tutorial
Sriram's Breakpoint Info

Quick Reference

Load sos.dll whenever mscorwks is loaded:
sxe -c ".loadby sos mscorwks;g" ld mscorwks.dll

Stop on CLR exception (code e0434f4d):
sxe e0434f4d

Dump the memory address pointed to by some hex memory address:
du poi(ABCD3210)

Start a log file of all commands:
.logopen c:\logfile.log