System.Diagnostics.StackTrace

P

Peter Larsen [CPH]

Hi,

How do i get the line number of the calling method in debug-mode.
This is what i do:

StackTrace st = new StackTrace();
string s = string.Format("Method:{0}, line:{1}",
st.GetFrame(1).GetMethod(), "??");


This method gets the callers function name, but i don't know how to get the
line number.
Is it possible to get the same line number as shown in Visual Studio ??

Thank you in advance.
BR
Peter
 
J

Jeffrey Tan[MSFT]

Hi Peter,

Yes, StackFrame.GetFileLineNumber() method should meet your need. Please
note that source code line information is only contained in the private
debugging symbol files instead of the .Net assembly. This means that your
application must always generate the PDB symbol file so that
StackFrame.GetFileLineNumber() method can retrieve source line information.
Normally, this should not be a problem in debug-mode, since debug-mode
generates PDB symbol files by default.

Furthermore, debug-mode does not equally mean the PDB symbol files. We can
also configure the VS compiler/linker to generate the PDB symbol files in
release build. This allows your application to use
StackFrame.GetFileLineNumber() method in release mode.

If you have anything unclear, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Peter,

Thank you for the confirmation.

If you need any further help, please feel free to post, I am glad to be any
help. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top