views:

90

answers:

2

MSDN says this about the StackTrace property of the Exception class:

The StackTrace property holds a stack trace, which you can use to determine where in the code the error occurred. StackTrace lists all the called methods that preceded the exception and the line numbers in the source where the calls were made.

So I know that this information is available. How do I get the line numbers to actually show up in the stack trace? My code is throwing an exception in a very difficult and complex piece of code that goes through TONS of objects, so I don't want to step through a bazillion times to see where the exception is happening. The stack trace of the exception only shows method signatures and no line numbers.

+4  A: 

You have to build the project with pdb files enabled and make sure your deploy the pdb files with your application. You can check if pdb files are in fact being built for you configuration by right clicking on the assembly you require pdb files for, then heading to Properties > Build > Advanced and making sure that under Output Debug Info is set to full.

Jaimal Chohan
My PDBs are there, and everything is set properly. Still a no go.
Scienceprodigy
+2  A: 

To get the line numbers in the StackTrace, you need to have the correct debug information (PDB files) alongside your dlls/exes. To generate the the debug information, set the option in Project Properties -> Build -> Advanced -> Debug Info:

alt text

Setting it to full should suffice (see the MSDN docs for what the other options do). Debug info (ie. PDB files) are generated for Debug build configurations by default, but can also be generated for Release build configurations.

Generating PDBs for release builds enables you to ship you code without the PDBs, but to drop the PDBs next to the dlls if you need line numbers (or even to attach a remote debugger). One thing to note is that in a release build, the line numbers may not be entirely correct due to optimisations made by the compiler or the JIT compiler (this is especially so if the line numbers show as 0).

adrianbanks