Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two things here:</p> <p>1) Make sure that the pdb files are present, otherwise you'll always get a zero.</p> <p>2) Be careful to make sure you are retrieving the correct stack frame. The current stack frame is the zeroth. As you walk up the stack, you will be walking up through your code, BUT above your code on the stack will be a load of framework calls to start the application, and these will have a zero line number.</p> <p>This bit of code illustrates this:</p> <pre><code>static void Main(string[] args) { WriteOutStack(); Console.ReadLine(); } public static void WriteOutStack() { StackTrace stackTrace = new StackTrace(true); for (int i = 0; i &lt; (stackTrace.FrameCount); i++) { StackFrame stackFrame = stackTrace.GetFrame(i); Console.WriteLine("{0}.{1} ({2})", stackFrame.GetMethod().DeclaringType.Name, stackFrame.GetMethod().Name, stackFrame.GetFileLineNumber()); } } </code></pre> <p>OUTPUT:</p> <pre><code>Program.WriteOutStack (20) Program.Main (15) AppDomain._nExecuteAssembly (0) HostProc.RunUsersAssembly (0) ExecutionContext.Run (0) ThreadHelper.ThreadStart (0) </code></pre> <p>The output above shows that once I've walked through the two layers that constitute my code, I am into the framework itself for which no line numbers are available.</p> <p>The main reason I mention this is I noticed, in your sample, you were getting a specific stack frame (frame 3) so I thought it worth raising. (In other words, make sure you don't read the stack upside down in the hand-rolled code you showed above).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload