How to get line number where error occured in stack trace

Topics: Exception Handling Application Block, Logging Application Block
Aug 25, 2009 at 11:51 AM


I am using ent lib 2006 and I am using the logging and exception handling application blocks to log my errors.

The stack trace information is not displaying the line number where the error occured and this is very frustrating. This is an example of the stack trace


at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) 
at System.String.Format(IFormatProvider provider, String format, Object[] args) 
at System.String.Format(String format, Object arg0) at SureTrack2.Server.TCPClientThread.Connect() 


I have seen the line numbers before in the stack trace given by the enterprise libray. The only difference i can think of is that this is a multi-threaded application and and Connect is the method called when the thread is started. Could this be the reason why? Is there any way i can get the line number?

many thanks

Aug 25, 2009 at 5:29 PM

Line numbers are maintained in the pdb files generated by compiling using the Debug configuration.  Make sure the pdb file is deployed along side your assembly.

good luck,



Aug 26, 2009 at 7:28 AM

Yes. You might want to try the suggestion of kstout.

Sep 1, 2009 at 11:36 PM


I hadn't deployed the pdb file. Perhaps this isn;t the right forum to ask but you might be kind enough to tell me what the pdb file is and why the line numbers for errors are stored there. I will look into this more myself too.


Sep 2, 2009 at 12:39 AM

Sep 2, 2009 at 12:02 PM


Thansk very much for your help. Deploying the dpb file restored the missing line number. However i still have a small problem because the line number given in the error message does not correspond to the line number in the code. Presumbably this is because the code is in 2 separate files. I have one file which is simply a main() method that runs in a continuous loop starting separate threads when appropriate, and another file containing the code for the thread. The error is occuring in the thread file. The line number given in the stack trace does not match any any line in the thread code that could cause the error encountered. Is there anything i can do about this? Can you 'merge' the files somehow to find out the line number?


Sep 2, 2009 at 12:16 PM


I think i'm wrong now because i think that line of code could cause the error. The error message was very misleading!