13

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?

SilverLight
  • 19,668
  • 65
  • 192
  • 300

1 Answers1

11

Try

System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
var stackFrame = trace.GetFrame(trace.FrameCount - 1);
var lineNumber = stackFrame.GetFileLineNumber();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939