Thursday 1 April 2010

Line numbers in stack trace

When a .net application fails and an exception is thrown you may want to find the reason for such behavior. To identify the code that caused the exception you can examine the stack trace included in your exception. However, the stack trace may not contain line number, which makes the failing code harder to find, especially if you have a lot of code in single methods (not recommended).

Solution:
To ensure that line numbers are included in stack trace you need to deploy .pdb files together with your dll-s. Program database (pdb) files are created when you build your app in Debug mode. You need to copy them to the same directory where dll-s are placed.

Tip: GAC dll-s are stored under folder structure described here

1 comment:

Jaroslaw Dobrzanski said...

Even if you don't keep pdb's on the target computer, where your application crashes, you can still collect a (mini) dump and load it in debugger (WinDBG, Visual Studio).

Once you start debugging, you can link the debugger with that symbol file and you will be getting much more than just the line numbers - you will do post mortem debugging. See more details there