14

I'm using VS2010 to develop my project. In my codebase, I use the stackframe's GetFileLineNumber() function. At runtime, however, it always returns 0. This happens even though I am running a debug build. I have also confirmed that the generated pdb file exists alongside the generated executable.

Any ideas?

Stephen Gross
  • 5,274
  • 12
  • 41
  • 59

1 Answers1

29

Aha! I found the information squirreled away at the bottom of MS' reference post:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.getfilelinenumber(v=vs.80).aspx

Turns out you have to construct your StackTrace instance like so:

st = new StackTrace(true);

The true gets you file & line info.

Stephen Gross
  • 5,274
  • 12
  • 41
  • 59