Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetFileLineNumber() returns 0, even though I'm using a debug build

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?

like image 264
Stephen Gross Avatar asked Feb 27 '12 20:02

Stephen Gross


1 Answers

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.

like image 54
Stephen Gross Avatar answered Nov 09 '22 09:11

Stephen Gross