[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

System.Diagnostics.StackTrace

Peter Larsen [CPH]

4/28/2008 2:32:00 PM

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


4 Answers

AMercer

4/28/2008 3:29:00 PM

0

Use GetFileLineNumber in StackFrame.

"Peter Larsen [CPH]" wrote:

> 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
>
>
>

jetan

4/29/2008 2:41:00 AM

0

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:
msdnmg@microsoft.com.

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

Peter Larsen [CPH]

4/29/2008 1:37:00 PM

0

Hi,

Thank you for your comments (and answers).

/Peter


jetan

4/30/2008 2:04:00 AM

0

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:
msdnmg@microsoft.com.

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