Question

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?

Was it helpful?

Solution

Try

System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
var stackFrame = trace.GetFrame(trace.FrameCount - 1);
var lineNumber = stackFrame.GetFileLineNumber();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top