How can I get current line number, function name, etc. like in C++?

K

Ken Varn

I want to be able to determine my current line, file, and function in my C#
application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___
macros for getting this, but I cannot find a C# equivalent. Any ideas?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.
(e-mail address removed)
-----------------------------------
 
J

Jonathan Schafer

I think you can get at least some of this from the StackFrame class.

Jonathan Schafer
 
K

Ken Varn

I have used the stack frame for this, but the only problem is that I am
contemplating using a .net code obfuscator and I am concerned that this
information will not be readable as runtime data. I would prefer to be able
to get it at compile time if possible.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.
(e-mail address removed)
-----------------------------------
 
J

Jeffrey Tan[MSFT]

Hi Ken,

In C#, you can use System.Diagnostics.StackTrace class to get the code’s
line number, function name, filename and other information.
My sample code was listed below:

using System;
using System.Diagnostics ;

namespace getline
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
StackTrace st=new StackTrace (0,true);

StackFrame sf=new StackFrame ();
sf=st.GetFrame (0);
Console.WriteLine ("FileName: {0}",sf.GetFileName ());
Console.WriteLine ("Line Number:
{0}",sf.GetFileLineNumber ());
Console.WriteLine ("Function Name:
{0}",sf.GetMethod ());

Console.Read ();
}
}
}

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Ken Varn" <[email protected]>
| From: "Ken Varn" <[email protected]>
| Subject: How can I get current line number, function name, etc. like in
C++?
| Date: Tue, 29 Jul 2003 16:02:50 -0400
| Lines: 13
| Organization: Diebold Inc.
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:172768
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I want to be able to determine my current line, file, and function in my
C#
| application. I know that C++ has the __LINE__, __FUNCTION__, and
__FILE___
| macros for getting this, but I cannot find a C# equivalent. Any ideas?
|
| --
| -----------------------------------
| Ken Varn
| Senior Software Engineer
| Diebold Inc.
| (e-mail address removed)
| -----------------------------------
|
|
|
 
K

Ken Varn

I have tried using this with some success, but it does not seem to work well
with using the Release version of code.

Also, we are considering using a code obfuscator, and this would also
prevent things like function name from being valid when obtaining it at run
time. I would prefer a compile time method if possible.

--
 
C

Chad Yost

Ken,

I have tried this, but it doesn't work in a release build, even if we
create the PDB file. Is there a way to get it to work in release? We
would like to use this for logging errors that need to be looked at,
but don't effect our users experience.


BTW, any exceptions that are thrown, the call stack in those also does
not have any line numbers or filenames.

chad
 
J

Jeffrey Tan[MSFT]

Hi Ken,

You can find the following remark in MSDN:

"StackTrace information will be most informative with Debug build
configurations. By default, Debug builds include debug symbols, while
Release builds do not. The debug symbols contain most of the file, method
name, line number, and column information used in constructing StackFrame
and StackTrace objects. StackTrace might not report as many method calls as
expected, due to code transformations that occur during optimization."

If you really want to still get full info in release builds (without
obfuscation), then go to Project/Properties select Configuration
Properties/Build and set the following:

1.Optimize Code false
2.Generate Debugging Information true

Per the obfuscation bit, the point of it is to deny folks the opportunity
to reverse-engineer your code. The ability to get a good stack trace from
obfuscated code would defeat the reasons for obfuscation

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Ken Varn" <[email protected]>
| From: "Ken Varn" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| Date: Wed, 30 Jul 2003 11:48:21 -0400
| Lines: 94
| Organization: Diebold Inc.
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:172994
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have tried using this with some success, but it does not seem to work
well
| with using the Release version of code.
|
| Also, we are considering using a code obfuscator, and this would also
| prevent things like function name from being valid when obtaining it at
run
| time. I would prefer a compile time method if possible.
|
| --
| -----------------------------------
| Ken Varn
| Senior Software Engineer
| Diebold Inc.
| (e-mail address removed)
| -----------------------------------
| | >
| > Hi Ken,
| >
| > In C#, you can use System.Diagnostics.StackTrace class to get the code's
| > line number, function name, filename and other information.
| > My sample code was listed below:
| >
| > using System;
| > using System.Diagnostics ;
| >
| > namespace getline
| > {
| > class Class1
| > {
| > [STAThread]
| > static void Main(string[] args)
| > {
| > StackTrace st=new StackTrace (0,true);
| >
| > StackFrame sf=new StackFrame ();
| > sf=st.GetFrame (0);
| > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| > Console.WriteLine ("Line Number:
| > {0}",sf.GetFileLineNumber ());
| > Console.WriteLine ("Function Name:
| > {0}",sf.GetMethod ());
| >
| > Console.Read ();
| > }
| > }
| > }
| >
| > Hope this helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Ken Varn" <[email protected]>
| > | From: "Ken Varn" <[email protected]>
| > | Subject: How can I get current line number, function name, etc. like
in
| > C++?
| > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| > | Lines: 13
| > | Organization: Diebold Inc.
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:172768
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I want to be able to determine my current line, file, and function in
my
| > C#
| > | application. I know that C++ has the __LINE__, __FUNCTION__, and
| > __FILE___
| > | macros for getting this, but I cannot find a C# equivalent. Any
ideas?
| > |
| > | --
| > | -----------------------------------
| > | Ken Varn
| > | Senior Software Engineer
| > | Diebold Inc.
| > | (e-mail address removed)
| > | -----------------------------------
| > |
| > |
| > |
| >
|
|
|
 
K

Ken Varn

In regards to obfuscation, I understand your point. However, as you
stated, I am trying to keep others from reverse engineering my code, not
myself. I still need the stack trace data to be able to troubleshoot
problems in the field. If some of this information were available only at
compile time (such as function, line number, etc..), then I would be the
only one accessing it, not anyone else. I was able to accomplish this in
C++ using __LINE__, __FILE__, and __FUNCTION__, but not in C#.


--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.
(e-mail address removed)
-----------------------------------
Jeffrey Tan said:
Hi Ken,

You can find the following remark in MSDN:

"StackTrace information will be most informative with Debug build
configurations. By default, Debug builds include debug symbols, while
Release builds do not. The debug symbols contain most of the file, method
name, line number, and column information used in constructing StackFrame
and StackTrace objects. StackTrace might not report as many method calls as
expected, due to code transformations that occur during optimization."

If you really want to still get full info in release builds (without
obfuscation), then go to Project/Properties select Configuration
Properties/Build and set the following:

1.Optimize Code false
2.Generate Debugging Information true

Per the obfuscation bit, the point of it is to deny folks the opportunity
to reverse-engineer your code. The ability to get a good stack trace from
obfuscated code would defeat the reasons for obfuscation

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Ken Varn" <[email protected]>
| From: "Ken Varn" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| Date: Wed, 30 Jul 2003 11:48:21 -0400
| Lines: 94
| Organization: Diebold Inc.
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:172994
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have tried using this with some success, but it does not seem to work
well
| with using the Release version of code.
|
| Also, we are considering using a code obfuscator, and this would also
| prevent things like function name from being valid when obtaining it at
run
| time. I would prefer a compile time method if possible.
|
| --
| -----------------------------------
| Ken Varn
| Senior Software Engineer
| Diebold Inc.
| (e-mail address removed)
| -----------------------------------
| | >
| > Hi Ken,
| >
| > In C#, you can use System.Diagnostics.StackTrace class to get the code's
| > line number, function name, filename and other information.
| > My sample code was listed below:
| >
| > using System;
| > using System.Diagnostics ;
| >
| > namespace getline
| > {
| > class Class1
| > {
| > [STAThread]
| > static void Main(string[] args)
| > {
| > StackTrace st=new StackTrace (0,true);
| >
| > StackFrame sf=new StackFrame ();
| > sf=st.GetFrame (0);
| > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| > Console.WriteLine ("Line Number:
| > {0}",sf.GetFileLineNumber ());
| > Console.WriteLine ("Function Name:
| > {0}",sf.GetMethod ());
| >
| > Console.Read ();
| > }
| > }
| > }
| >
| > Hope this helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Ken Varn" <[email protected]>
| > | From: "Ken Varn" <[email protected]>
| > | Subject: How can I get current line number, function name, etc. like
in
| > C++?
| > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| > | Lines: 13
| > | Organization: Diebold Inc.
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:172768
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I want to be able to determine my current line, file, and function in
my
| > C#
| > | application. I know that C++ has the __LINE__, __FUNCTION__, and
| > __FILE___
| > | macros for getting this, but I cannot find a C# equivalent. Any
ideas?
| > |
| > | --
| > | -----------------------------------
| > | Ken Varn
| > | Senior Software Engineer
| > | Diebold Inc.
| > | (e-mail address removed)
| > | -----------------------------------
| > |
| > |
| > |
| >
|
|
|
 
J

Jeffrey Tan[MSFT]

Hi Ken,

So I provided you a solution of turning off the code optimize, then you can
use it in the release mode.
And your teammate also can use it to get these information.

Go to Project/Properties select Configuration
Properties/Build and set the following:

1.Optimize Code false
2.Generate Debugging Information true

After finishing getting your information, you can obfuscate your
application.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Ken Varn" <[email protected]>
| From: "Ken Varn" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| Date: Mon, 4 Aug 2003 09:48:07 -0400
| Lines: 179
| Organization: Diebold Inc.
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:173974
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| In regards to obfuscation, I understand your point. However, as you
| stated, I am trying to keep others from reverse engineering my code, not
| myself. I still need the stack trace data to be able to troubleshoot
| problems in the field. If some of this information were available only at
| compile time (such as function, line number, etc..), then I would be the
| only one accessing it, not anyone else. I was able to accomplish this in
| C++ using __LINE__, __FILE__, and __FUNCTION__, but not in C#.
|
|
| --
| -----------------------------------
| Ken Varn
| Senior Software Engineer
| Diebold Inc.
| (e-mail address removed)
| -----------------------------------
| | >
| > Hi Ken,
| >
| > You can find the following remark in MSDN:
| >
| > "StackTrace information will be most informative with Debug build
| > configurations. By default, Debug builds include debug symbols, while
| > Release builds do not. The debug symbols contain most of the file,
method
| > name, line number, and column information used in constructing
StackFrame
| > and StackTrace objects. StackTrace might not report as many method calls
| as
| > expected, due to code transformations that occur during optimization."
| >
| > If you really want to still get full info in release builds (without
| > obfuscation), then go to Project/Properties select Configuration
| > Properties/Build and set the following:
| >
| > 1.Optimize Code false
| > 2.Generate Debugging Information true
| >
| > Per the obfuscation bit, the point of it is to deny folks the
opportunity
| > to reverse-engineer your code. The ability to get a good stack trace
from
| > obfuscated code would defeat the reasons for obfuscation
| >
| > Hope this helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Ken Varn" <[email protected]>
| > | From: "Ken Varn" <[email protected]>
| > | References: <#[email protected]>
| > <[email protected]>
| > | Subject: Re: How can I get current line number, function name, etc.
| like
| > in C++?
| > | Date: Wed, 30 Jul 2003 11:48:21 -0400
| > | Lines: 94
| > | Organization: Diebold Inc.
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:172994
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I have tried using this with some success, but it does not seem to
work
| > well
| > | with using the Release version of code.
| > |
| > | Also, we are considering using a code obfuscator, and this would also
| > | prevent things like function name from being valid when obtaining it
at
| > run
| > | time. I would prefer a compile time method if possible.
| > |
| > | --
| > | -----------------------------------
| > | Ken Varn
| > | Senior Software Engineer
| > | Diebold Inc.
| > | (e-mail address removed)
| > | -----------------------------------
| > | | > | >
| > | > Hi Ken,
| > | >
| > | > In C#, you can use System.Diagnostics.StackTrace class to get the
| code's
| > | > line number, function name, filename and other information.
| > | > My sample code was listed below:
| > | >
| > | > using System;
| > | > using System.Diagnostics ;
| > | >
| > | > namespace getline
| > | > {
| > | > class Class1
| > | > {
| > | > [STAThread]
| > | > static void Main(string[] args)
| > | > {
| > | > StackTrace st=new StackTrace (0,true);
| > | >
| > | > StackFrame sf=new StackFrame ();
| > | > sf=st.GetFrame (0);
| > | > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| > | > Console.WriteLine ("Line Number:
| > | > {0}",sf.GetFileLineNumber ());
| > | > Console.WriteLine ("Function Name:
| > | > {0}",sf.GetMethod ());
| > | >
| > | > Console.Read ();
| > | > }
| > | > }
| > | > }
| > | >
| > | > Hope this helps.
| > | >
| > | > Jeffrey Tan
| > | > Microsoft Online Partner Support
| > | > Get Secure! - www.microsoft.com/security
| > | > This posting is provided "as is" with no warranties and confers no
| > rights.
| > | >
| > | > --------------------
| > | > | Reply-To: "Ken Varn" <[email protected]>
| > | > | From: "Ken Varn" <[email protected]>
| > | > | Subject: How can I get current line number, function name, etc.
| like
| > in
| > | > C++?
| > | > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| > | > | Lines: 13
| > | > | Organization: Diebold Inc.
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | > | Xref: cpmsftngxa06.phx.gbl
| > | microsoft.public.dotnet.languages.csharp:172768
| > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > |
| > | > | I want to be able to determine my current line, file, and function
| in
| > my
| > | > C#
| > | > | application. I know that C++ has the __LINE__, __FUNCTION__, and
| > | > __FILE___
| > | > | macros for getting this, but I cannot find a C# equivalent. Any
| > ideas?
| > | > |
| > | > | --
| > | > | -----------------------------------
| > | > | Ken Varn
| > | > | Senior Software Engineer
| > | > | Diebold Inc.
| > | > | (e-mail address removed)
| > | > | -----------------------------------
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
C

Chad Yost

Jeffrey,

I have tried this, and I still can't get filename and line numbers in
release builds. Is there something I am missing... BTW, this is an
ASP.NET app.

chad

Hi Ken,

So I provided you a solution of turning off the code optimize, then you can
use it in the release mode.
And your teammate also can use it to get these information.

Go to Project/Properties select Configuration
Properties/Build and set the following:

1.Optimize Code false
2.Generate Debugging Information true

After finishing getting your information, you can obfuscate your
application.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Ken Varn" <[email protected]>
| From: "Ken Varn" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| Date: Mon, 4 Aug 2003 09:48:07 -0400
| Lines: 179
| Organization: Diebold Inc.
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:173974
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| In regards to obfuscation, I understand your point. However, as you
| stated, I am trying to keep others from reverse engineering my code, not
| myself. I still need the stack trace data to be able to troubleshoot
| problems in the field. If some of this information were available only at
| compile time (such as function, line number, etc..), then I would be the
| only one accessing it, not anyone else. I was able to accomplish this in
| C++ using __LINE__, __FILE__, and __FUNCTION__, but not in C#.
|
|
| --
| -----------------------------------
| Ken Varn
| Senior Software Engineer
| Diebold Inc.
| (e-mail address removed)
| -----------------------------------
| | >
| > Hi Ken,
| >
| > You can find the following remark in MSDN:
| >
| > "StackTrace information will be most informative with Debug build
| > configurations. By default, Debug builds include debug symbols, while
| > Release builds do not. The debug symbols contain most of the file,
method
| > name, line number, and column information used in constructing
StackFrame
| > and StackTrace objects. StackTrace might not report as many method calls
as
| > expected, due to code transformations that occur during optimization."
| >
| > If you really want to still get full info in release builds (without
| > obfuscation), then go to Project/Properties select Configuration
| > Properties/Build and set the following:
| >
| > 1.Optimize Code false
| > 2.Generate Debugging Information true
| >
| > Per the obfuscation bit, the point of it is to deny folks the
opportunity
| > to reverse-engineer your code. The ability to get a good stack trace
from
| > obfuscated code would defeat the reasons for obfuscation
| >
| > Hope this helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Ken Varn" <[email protected]>
| > | From: "Ken Varn" <[email protected]>
| > | References: <#[email protected]>
<[email protected]>
| > | Subject: Re: How can I get current line number, function name, etc.
like
in C++?
| > | Date: Wed, 30 Jul 2003 11:48:21 -0400
| > | Lines: 94
| > | Organization: Diebold Inc.
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:172994
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I have tried using this with some success, but it does not seem to
work
well
| > | with using the Release version of code.
| > |
| > | Also, we are considering using a code obfuscator, and this would also
| > | prevent things like function name from being valid when obtaining it
at
run
| > | time. I would prefer a compile time method if possible.
| > |
| > | --
| > | -----------------------------------
| > | Ken Varn
| > | Senior Software Engineer
| > | Diebold Inc.
| > | (e-mail address removed)
| > | -----------------------------------
| > | | > | >
| > | > Hi Ken,
| > | >
| > | > In C#, you can use System.Diagnostics.StackTrace class to get the
code's
| > | > line number, function name, filename and other information.
| > | > My sample code was listed below:
| > | >
| > | > using System;
| > | > using System.Diagnostics ;
| > | >
| > | > namespace getline
| > | > {
| > | > class Class1
| > | > {
| > | > [STAThread]
| > | > static void Main(string[] args)
| > | > {
| > | > StackTrace st=new StackTrace (0,true);
| > | >
| > | > StackFrame sf=new StackFrame ();
| > | > sf=st.GetFrame (0);
| > | > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| > | > Console.WriteLine ("Line Number:
| > | > {0}",sf.GetFileLineNumber ());
| > | > Console.WriteLine ("Function Name:
| > | > {0}",sf.GetMethod ());
| > | >
| > | > Console.Read ();
| > | > }
| > | > }
| > | > }
| > | >
| > | > Hope this helps.
| > | >
| > | > Jeffrey Tan
| > | > Microsoft Online Partner Support
| > | > Get Secure! - www.microsoft.com/security
| > | > This posting is provided "as is" with no warranties and confers no
rights.
| > | >
| > | > --------------------
| > | > | Reply-To: "Ken Varn" <[email protected]>
| > | > | From: "Ken Varn" <[email protected]>
| > | > | Subject: How can I get current line number, function name, etc.
like
in
C++?
| > | > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| > | > | Lines: 13
| > | > | Organization: Diebold Inc.
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:172768
| > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > |
| > | > | I want to be able to determine my current line, file, and function
in
my
C#
| > | > | application. I know that C++ has the __LINE__, __FUNCTION__, and
__FILE___
| > | > | macros for getting this, but I cannot find a C# equivalent. Any
ideas?
| > | > |
| > | > | --
| > | > | -----------------------------------
| > | > | Ken Varn
| > | > | Senior Software Engineer
| > | > | Diebold Inc.
| > | > | (e-mail address removed)
| > | > | -----------------------------------
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
J

Jeffrey Tan[MSFT]

Hi cyost,

Are you sure you have followed my steps to close the code optimization and
add debug information?
On my machine, after these two steps, the release application worked well.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: (e-mail address removed) (Chad Yost)
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| Date: 6 Aug 2003 07:30:01 -0700
| Organization: http://groups.google.com/
| Lines: 240
| Message-ID: <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<AE6W8h#[email protected]>
| NNTP-Posting-Host: 167.68.1.65
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1060180202 14222 127.0.0.1 (6 Aug 2003
14:30:02 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: 6 Aug 2003 14:30:02 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!in.10
0proofnews.com!in.100proofnews.com!elnk-atl-nf1!newsfeed.earthlink.net!newsh
osting.com!news-xfer2.atl.newshosting.com!diablo.voicenet.com!tdsnet-transit
!newspeer.tds.net!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!post
news1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:174622
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Jeffrey,
|
| I have tried this, and I still can't get filename and line numbers in
| release builds. Is there something I am missing... BTW, this is an
| ASP.NET app.
|
| chad
|
| (e-mail address removed) (Jeffrey Tan[MSFT]) wrote in message
| > Hi Ken,
| >
| > So I provided you a solution of turning off the code optimize, then you
can
| > use it in the release mode.
| > And your teammate also can use it to get these information.
| >
| > Go to Project/Properties select Configuration
| > Properties/Build and set the following:
| >
| > 1.Optimize Code false
| > 2.Generate Debugging Information true
| >
| > After finishing getting your information, you can obfuscate your
| > application.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Ken Varn" <[email protected]>
| > | From: "Ken Varn" <[email protected]>
| > | References: <#[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Subject: Re: How can I get current line number, function name, etc.
like
| > in C++?
| > | Date: Mon, 4 Aug 2003 09:48:07 -0400
| > | Lines: 179
| > | Organization: Diebold Inc.
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:173974
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | In regards to obfuscation, I understand your point. However, as you
| > | stated, I am trying to keep others from reverse engineering my code,
not
| > | myself. I still need the stack trace data to be able to troubleshoot
| > | problems in the field. If some of this information were available
only at
| > | compile time (such as function, line number, etc..), then I would be
the
| > | only one accessing it, not anyone else. I was able to accomplish
this in
| > | C++ using __LINE__, __FILE__, and __FUNCTION__, but not in C#.
| > |
| > |
| > | --
| > | -----------------------------------
| > | Ken Varn
| > | Senior Software Engineer
| > | Diebold Inc.
| > | (e-mail address removed)
| > | -----------------------------------
| > | | > | >
| > | > Hi Ken,
| > | >
| > | > You can find the following remark in MSDN:
| > | >
| > | > "StackTrace information will be most informative with Debug build
| > | > configurations. By default, Debug builds include debug symbols,
while
| > | > Release builds do not. The debug symbols contain most of the file,
| > method
| > | > name, line number, and column information used in constructing
| > StackFrame
| > | > and StackTrace objects. StackTrace might not report as many method
calls
| > as
| > | > expected, due to code transformations that occur during
optimization."
| > | >
| > | > If you really want to still get full info in release builds (without
| > | > obfuscation), then go to Project/Properties select Configuration
| > | > Properties/Build and set the following:
| > | >
| > | > 1.Optimize Code false
| > | > 2.Generate Debugging Information true
| > | >
| > | > Per the obfuscation bit, the point of it is to deny folks the
| > opportunity
| > | > to reverse-engineer your code. The ability to get a good stack
trace
| > from
| > | > obfuscated code would defeat the reasons for obfuscation
| > | >
| > | > Hope this helps.
| > | >
| > | > Jeffrey Tan
| > | > Microsoft Online Partner Support
| > | > Get Secure! - www.microsoft.com/security
| > | > This posting is provided "as is" with no warranties and confers no
| > rights.
| > | >
| > | > --------------------
| > | > | Reply-To: "Ken Varn" <[email protected]>
| > | > | From: "Ken Varn" <[email protected]>
| > | > | References: <#[email protected]>
| > <[email protected]>
| > | > | Subject: Re: How can I get current line number, function name,
etc.
| > like
| > in C++?
| > | > | Date: Wed, 30 Jul 2003 11:48:21 -0400
| > | > | Lines: 94
| > | > | Organization: Diebold Inc.
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.languages.csharp:172994
| > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > |
| > | > | I have tried using this with some success, but it does not seem
to
| > work
| > well
| > | > | with using the Release version of code.
| > | > |
| > | > | Also, we are considering using a code obfuscator, and this would
also
| > | > | prevent things like function name from being valid when obtaining
it
| > at
| > run
| > | > | time. I would prefer a compile time method if possible.
| > | > |
| > | > | --
| > | > | -----------------------------------
| > | > | Ken Varn
| > | > | Senior Software Engineer
| > | > | Diebold Inc.
| > | > | (e-mail address removed)
| > | > | -----------------------------------
message
| > | > | | > | > | >
| > | > | > Hi Ken,
| > | > | >
| > | > | > In C#, you can use System.Diagnostics.StackTrace class to get
the
| > code's
| > | > | > line number, function name, filename and other information.
| > | > | > My sample code was listed below:
| > | > | >
| > | > | > using System;
| > | > | > using System.Diagnostics ;
| > | > | >
| > | > | > namespace getline
| > | > | > {
| > | > | > class Class1
| > | > | > {
| > | > | > [STAThread]
| > | > | > static void Main(string[] args)
| > | > | > {
| > | > | > StackTrace st=new StackTrace (0,true);
| > | > | >
| > | > | > StackFrame sf=new StackFrame ();
| > | > | > sf=st.GetFrame (0);
| > | > | > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| > | > | > Console.WriteLine ("Line
Number:
| > | > | > {0}",sf.GetFileLineNumber ());
| > | > | > Console.WriteLine ("Function
Name:
| > | > | > {0}",sf.GetMethod ());
| > | > | >
| > | > | > Console.Read ();
| > | > | > }
| > | > | > }
| > | > | > }
| > | > | >
| > | > | > Hope this helps.
| > | > | >
| > | > | > Jeffrey Tan
| > | > | > Microsoft Online Partner Support
| > | > | > Get Secure! - www.microsoft.com/security
| > | > | > This posting is provided "as is" with no warranties and confers
no
| > rights.
| > | > | >
| > | > | > --------------------
| > | > | > | Reply-To: "Ken Varn" <[email protected]>
| > | > | > | From: "Ken Varn" <[email protected]>
| > | > | > | Subject: How can I get current line number, function name,
etc.
| > like
| > in
| > C++?
| > | > | > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| > | > | > | Lines: 13
| > | > | > | Organization: Diebold Inc.
| > | > | > | X-Priority: 3
| > | > | > | X-MSMail-Priority: Normal
| > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | > | Message-ID: <#[email protected]>
| > | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | > | Path:
| > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | > | > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.languages.csharp:172768
| > | > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > | > |
| > | > | > | I want to be able to determine my current line, file, and
function
| > in
| > my
| > C#
| > | > | > | application. I know that C++ has the __LINE__, __FUNCTION__,
and
| > __FILE___
| > | > | > | macros for getting this, but I cannot find a C# equivalent.
Any
| > ideas?
| > | > | > |
| > | > | > | --
| > | > | > | -----------------------------------
| > | > | > | Ken Varn
| > | > | > | Senior Software Engineer
| > | > | > | Diebold Inc.
| > | > | > | (e-mail address removed)
| > | > | > | -----------------------------------
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
|
 
J

Jeffrey Tan[MSFT]

Hi cyost,

Is there still any unclear?
Please feel free to let me know, I am glad I can help you.

Best regards,

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| X-Tomcat-ID: 132354918
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<AE6W8h#[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Jeffrey Tan[MSFT])
| Organization: Microsoft
| Date: Thu, 07 Aug 2003 06:14:58 GMT
| Subject: Re: How can I get current line number, function name, etc. like
in C++?
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Lines: 280
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:174774
| NNTP-Posting-Host: TOMCATIMPORT2 10.201.218.182
|
|
| Hi cyost,
|
| Are you sure you have followed my steps to close the code optimization
and
| add debug information?
| On my machine, after these two steps, the release application worked well.
|
| Jeffrey Tan
| Microsoft Online Partner Support
| Get Secure! - www.microsoft.com/security
| This posting is provided "as is" with no warranties and confers no rights.
|
| --------------------
| | From: (e-mail address removed) (Chad Yost)
| | Newsgroups: microsoft.public.dotnet.languages.csharp
| | Subject: Re: How can I get current line number, function name, etc.
like
| in C++?
| | Date: 6 Aug 2003 07:30:01 -0700
| | Organization: http://groups.google.com/
| | Lines: 240
| | Message-ID: <[email protected]>
| | References: <#[email protected]>
| <[email protected]>
| <[email protected]>
| <[email protected]>
| <#[email protected]>
| <AE6W8h#[email protected]>
| | NNTP-Posting-Host: 167.68.1.65
| | Content-Type: text/plain; charset=ISO-8859-1
| | Content-Transfer-Encoding: 8bit
| | X-Trace: posting.google.com 1060180202 14222 127.0.0.1 (6 Aug 2003
| 14:30:02 GMT)
| | X-Complaints-To: (e-mail address removed)
| | NNTP-Posting-Date: 6 Aug 2003 14:30:02 GMT
| | Path:
|
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfee
|
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!in.10
|
0proofnews.com!in.100proofnews.com!elnk-atl-nf1!newsfeed.earthlink.net!newsh
|
osting.com!news-xfer2.atl.newshosting.com!diablo.voicenet.com!tdsnet-transit
|
!newspeer.tds.net!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!post
| news1.google.com!not-for-mail
| | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:174622
| | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| |
| | Jeffrey,
| |
| | I have tried this, and I still can't get filename and line numbers in
| | release builds. Is there something I am missing... BTW, this is an
| | ASP.NET app.
| |
| | chad
| |
| | (e-mail address removed) (Jeffrey Tan[MSFT]) wrote in message
| | | > Hi Ken,
| | >
| | > So I provided you a solution of turning off the code optimize, then
you
| can
| | > use it in the release mode.
| | > And your teammate also can use it to get these information.
| | >
| | > Go to Project/Properties select Configuration
| | > Properties/Build and set the following:
| | >
| | > 1.Optimize Code false
| | > 2.Generate Debugging Information true
| | >
| | > After finishing getting your information, you can obfuscate your
| | > application.
| | >
| | > Jeffrey Tan
| | > Microsoft Online Partner Support
| | > Get Secure! - www.microsoft.com/security
| | > This posting is provided "as is" with no warranties and confers no
| rights.
| | >
| | > --------------------
| | > | Reply-To: "Ken Varn" <[email protected]>
| | > | From: "Ken Varn" <[email protected]>
| | > | References: <#[email protected]>
| | > <[email protected]>
| | > <[email protected]>
| | > <[email protected]>
| | > | Subject: Re: How can I get current line number, function name, etc.

| like
| | > in C++?
| | > | Date: Mon, 4 Aug 2003 09:48:07 -0400
| | > | Lines: 179
| | > | Organization: Diebold Inc.
| | > | X-Priority: 3
| | > | X-MSMail-Priority: Normal
| | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| | > | Message-ID: <#[email protected]>
| | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | NNTP-Posting-Host: 204.151.249.23
| | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| | > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:173974
| | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| | > |
| | > | In regards to obfuscation, I understand your point. However, as
you
| | > | stated, I am trying to keep others from reverse engineering my
code,
| not
| | > | myself. I still need the stack trace data to be able to
troubleshoot
| | > | problems in the field. If some of this information were available
| only at
| | > | compile time (such as function, line number, etc..), then I would
be
| the
| | > | only one accessing it, not anyone else. I was able to accomplish
| this in
| | > | C++ using __LINE__, __FILE__, and __FUNCTION__, but not in C#.
| | > |
| | > |
| | > | --
| | > | -----------------------------------
| | > | Ken Varn
| | > | Senior Software Engineer
| | > | Diebold Inc.
| | > | (e-mail address removed)
| | > | -----------------------------------
| | > | | | > | >
| | > | > Hi Ken,
| | > | >
| | > | > You can find the following remark in MSDN:
| | > | >
| | > | > "StackTrace information will be most informative with Debug build
| | > | > configurations. By default, Debug builds include debug symbols,
| while
| | > | > Release builds do not. The debug symbols contain most of the
file,
| | > method
| | > | > name, line number, and column information used in constructing
| | > StackFrame
| | > | > and StackTrace objects. StackTrace might not report as many
method
| calls
| | > as
| | > | > expected, due to code transformations that occur during
| optimization."
| | > | >
| | > | > If you really want to still get full info in release builds
(without
| | > | > obfuscation), then go to Project/Properties select Configuration
| | > | > Properties/Build and set the following:
| | > | >
| | > | > 1.Optimize Code false
| | > | > 2.Generate Debugging Information true
| | > | >
| | > | > Per the obfuscation bit, the point of it is to deny folks the
| | > opportunity
| | > | > to reverse-engineer your code. The ability to get a good stack
| trace
| | > from
| | > | > obfuscated code would defeat the reasons for obfuscation
| | > | >
| | > | > Hope this helps.
| | > | >
| | > | > Jeffrey Tan
| | > | > Microsoft Online Partner Support
| | > | > Get Secure! - www.microsoft.com/security
| | > | > This posting is provided "as is" with no warranties and confers
no
| | > rights.
| | > | >
| | > | > --------------------
| | > | > | Reply-To: "Ken Varn" <[email protected]>
| | > | > | From: "Ken Varn" <[email protected]>
| | > | > | References: <#[email protected]>
| | > <[email protected]>
| | > | > | Subject: Re: How can I get current line number, function name,
| etc.
| | > like
| | > in C++?
| | > | > | Date: Wed, 30 Jul 2003 11:48:21 -0400
| | > | > | Lines: 94
| | > | > | Organization: Diebold Inc.
| | > | > | X-Priority: 3
| | > | > | X-MSMail-Priority: Normal
| | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| | > | > | Message-ID: <[email protected]>
| | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | > | NNTP-Posting-Host: 204.151.249.23
| | > | > | Path:
| cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| | > | > | Xref: cpmsftngxa06.phx.gbl
| | > microsoft.public.dotnet.languages.csharp:172994
| | > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| | > | > |
| | > | > | I have tried using this with some success, but it does not seem
| to
| | > work
| | > well
| | > | > | with using the Release version of code.
| | > | > |
| | > | > | Also, we are considering using a code obfuscator, and this
would
| also
| | > | > | prevent things like function name from being valid when
obtaining
| it
| | > at
| | > run
| | > | > | time. I would prefer a compile time method if possible.
| | > | > |
| | > | > | --
| | > | > | -----------------------------------
| | > | > | Ken Varn
| | > | > | Senior Software Engineer
| | > | > | Diebold Inc.
| | > | > | (e-mail address removed)
| | > | > | -----------------------------------
| message
| | > | > | | | > | > | >
| | > | > | > Hi Ken,
| | > | > | >
| | > | > | > In C#, you can use System.Diagnostics.StackTrace class to get
| the
| | > code's
| | > | > | > line number, function name, filename and other information.
| | > | > | > My sample code was listed below:
| | > | > | >
| | > | > | > using System;
| | > | > | > using System.Diagnostics ;
| | > | > | >
| | > | > | > namespace getline
| | > | > | > {
| | > | > | > class Class1
| | > | > | > {
| | > | > | > [STAThread]
| | > | > | > static void Main(string[] args)
| | > | > | > {
| | > | > | > StackTrace st=new StackTrace (0,true);
| | > | > | >
| | > | > | > StackFrame sf=new StackFrame ();
| | > | > | > sf=st.GetFrame (0);
| | > | > | > Console.WriteLine ("FileName: {0}",sf.GetFileName ());
| | > | > | > Console.WriteLine ("Line
| Number:
| | > | > | > {0}",sf.GetFileLineNumber ());
| | > | > | > Console.WriteLine ("Function
| Name:
| | > | > | > {0}",sf.GetMethod ());
| | > | > | >
| | > | > | > Console.Read ();
| | > | > | > }
| | > | > | > }
| | > | > | > }
| | > | > | >
| | > | > | > Hope this helps.
| | > | > | >
| | > | > | > Jeffrey Tan
| | > | > | > Microsoft Online Partner Support
| | > | > | > Get Secure! - www.microsoft.com/security
| | > | > | > This posting is provided "as is" with no warranties and
confers
| no
| | > rights.
| | > | > | >
| | > | > | > --------------------
| | > | > | > | Reply-To: "Ken Varn" <[email protected]>
| | > | > | > | From: "Ken Varn" <[email protected]>
| | > | > | > | Subject: How can I get current line number, function name,
| etc.
| | > like
| | > in
| | > C++?
| | > | > | > | Date: Tue, 29 Jul 2003 16:02:50 -0400
| | > | > | > | Lines: 13
| | > | > | > | Organization: Diebold Inc.
| | > | > | > | X-Priority: 3
| | > | > | > | X-MSMail-Priority: Normal
| | > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| | > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| | > | > | > | Message-ID: <#[email protected]>
| | > | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | > | > | NNTP-Posting-Host: 204.151.249.23
| | > | > | > | Path:
| | > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| | > | > | > | Xref: cpmsftngxa06.phx.gbl
| | > microsoft.public.dotnet.languages.csharp:172768
| | > | > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| | > | > | > |
| | > | > | > | I want to be able to determine my current line, file, and
| function
| | > in
| | > my
| | > C#
| | > | > | > | application. I know that C++ has the __LINE__,
__FUNCTION__,
| and
| | > __FILE___
| | > | > | > | macros for getting this, but I cannot find a C# equivalent.

| Any
| | > ideas?
| | > | > | > |
| | > | > | > | --
| | > | > | > | -----------------------------------
| | > | > | > | Ken Varn
| | > | > | > | Senior Software Engineer
| | > | > | > | Diebold Inc.
| | > | > | > | (e-mail address removed)
| | > | > | > | -----------------------------------
| | > | > | > |
| | > | > | > |
| | > | > | > |
| | > | > | >
| | > | > |
| | > | > |
| | > | > |
| | > | >
| | > |
| | > |
| | > |
| |
|
|
 

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