Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Exception Line Number Is Always Zero (0)

I published my project in debug mode and put both dll and pdb files in my server,
now i want to get exception line number using these codes :

   System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
   Response.Write("Line: " + trace.GetFrame(0).GetFileLineNumber());

but i don't know why line number of exception is always zero -> 0
how can i fix it?

like image 305
SilverLight Avatar asked Jan 16 '13 10:01

SilverLight


1 Answers

Try

System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
var stackFrame = trace.GetFrame(trace.FrameCount - 1);
var lineNumber = stackFrame.GetFileLineNumber();
like image 70
Tim Schmelter Avatar answered Oct 23 '22 03:10

Tim Schmelter