By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,633 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,633 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
va***@diebold.com
-----------------------------------
Nov 15 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
I think you can get at least some of this from the StackFrame class.

Jonathan Schafer

On Tue, 29 Jul 2003 16:02:50 -0400, "Ken Varn" <va***@diebold.com>
wrote:
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?


Nov 15 '05 #2

P: n/a

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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| va***@diebold.com
| -----------------------------------
|
|
|

Nov 15 '05 #3

P: n/a
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.
va***@diebold.com
-----------------------------------
"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:h3********************************@4ax.com...
I think you can get at least some of this from the StackFrame class.

Jonathan Schafer

On Tue, 29 Jul 2003 16:02:50 -0400, "Ken Varn" <va***@diebold.com>
wrote:
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?

Nov 15 '05 #4

P: n/a
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.
va***@diebold.com
-----------------------------------
"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:sq**************@cpmsftngxa06.phx.gbl...

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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| va***@diebold.com
| -----------------------------------
|
|
|

Nov 15 '05 #5

P: n/a
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

v-*****@online.microsoft.com (Jeffrey Tan[MSFT]) wrote in message news:<sq**************@cpmsftngxa06.phx.gbl>...
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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| va***@diebold.com
| -----------------------------------
|
|
|

Nov 15 '05 #6

P: n/a

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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
| 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: <eL**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| va***@diebold.com
| -----------------------------------
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:sq**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <va***@diebold.com>
| > | From: "Ken Varn" <va***@diebold.com>
| > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| > | va***@diebold.com
| > | -----------------------------------
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #7

P: n/a
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.
va***@diebold.com
-----------------------------------
"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:8$**************@cpmsftngxa06.phx.gbl...

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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
| 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: <eL**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| va***@diebold.com
| -----------------------------------
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:sq**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <va***@diebold.com>
| > | From: "Ken Varn" <va***@diebold.com>
| > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| > | va***@diebold.com
| > | -----------------------------------
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #8

P: n/a

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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
<eL**************@tk2msftngp13.phx.gbl>
<8$**************@cpmsftngxa06.phx.gbl>
| 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: <#z*************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.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.
| va***@diebold.com
| -----------------------------------
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:8$**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <va***@diebold.com>
| > | From: "Ken Varn" <va***@diebold.com>
| > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| > <sq**************@cpmsftngxa06.phx.gbl>
| > | 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: <eL**************@tk2msftngp13.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| > | va***@diebold.com
| > | -----------------------------------
| > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| > | news:sq**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <va***@diebold.com>
| > | > | From: "Ken Varn" <va***@diebold.com>
| > | > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| > | > | va***@diebold.com
| > | > | -----------------------------------
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #9

P: n/a
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

v-*****@online.microsoft.com (Jeffrey Tan[MSFT]) wrote in message news:<AE**************@cpmsftngxa06.phx.gbl>...
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" <va***@diebold.com>
| From: "Ken Varn" <va***@diebold.com>
| References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
<eL**************@tk2msftngp13.phx.gbl>
<8$**************@cpmsftngxa06.phx.gbl>
| 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: <#z*************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.151.249.23
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.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.
| va***@diebold.com
| -----------------------------------
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:8$**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <va***@diebold.com>
| > | From: "Ken Varn" <va***@diebold.com>
| > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
| > | 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: <eL**************@tk2msftngp13.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| > | va***@diebold.com
| > | -----------------------------------
| > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| > | news:sq**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <va***@diebold.com>
| > | > | From: "Ken Varn" <va***@diebold.com>
| > | > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| > | > | va***@diebold.com
| > | > | -----------------------------------
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #10

P: n/a

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: cy***@charter.net (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: <29**************************@posting.google.com >
| References: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
<eL**************@tk2msftngp13.phx.gbl>
<8$**************@cpmsftngxa06.phx.gbl>
<#z*************@TK2MSFTNGP10.phx.gbl>
<AE**************@cpmsftngxa06.phx.gbl>
| 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: gr**********@google.com
| NNTP-Posting-Date: 6 Aug 2003 14:30:02 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.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!tdsn et-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
|
| v-*****@online.microsoft.com (Jeffrey Tan[MSFT]) wrote in message
news:<AE**************@cpmsftngxa06.phx.gbl>...
| > 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" <va***@diebold.com>
| > | From: "Ken Varn" <va***@diebold.com>
| > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| > <sq**************@cpmsftngxa06.phx.gbl>
| > <eL**************@tk2msftngp13.phx.gbl>
| > <8$**************@cpmsftngxa06.phx.gbl>
| > | 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: <#z*************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.151.249.23
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.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.
| > | va***@diebold.com
| > | -----------------------------------
| > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| > | news:8$**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <va***@diebold.com>
| > | > | From: "Ken Varn" <va***@diebold.com>
| > | > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| > <sq**************@cpmsftngxa06.phx.gbl>
| > | > | 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: <eL**************@tk2msftngp13.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| > | > | va***@diebold.com
| > | > | -----------------------------------
| > | > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in
message
| > | > | news:sq**************@cpmsftngxa06.phx.gbl...
| > | > | >
| > | > | > 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" <va***@diebold.com>
| > | > | > | From: "Ken Varn" <va***@diebold.com>
| > | > | > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| > | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | > | NNTP-Posting-Host: 204.151.249.23
| > | > | > | Path:
| > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| > | > | > | va***@diebold.com
| > | > | > | -----------------------------------
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
|

Nov 15 '05 #11

P: n/a

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: <#w**************@TK2MSFTNGP11.phx.gbl>
<sq**************@cpmsftngxa06.phx.gbl>
<eL**************@tk2msftngp13.phx.gbl>
<8$**************@cpmsftngxa06.phx.gbl>
<#z*************@TK2MSFTNGP10.phx.gbl>
<AE**************@cpmsftngxa06.phx.gbl>
<29**************************@posting.google.com >
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: v-*****@online.microsoft.com (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: <ju**************@cpmsftngxa06.phx.gbl>
| 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: cy***@charter.net (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: <29**************************@posting.google.com >
| | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| <sq**************@cpmsftngxa06.phx.gbl>
| <eL**************@tk2msftngp13.phx.gbl>
| <8$**************@cpmsftngxa06.phx.gbl>
| <#z*************@TK2MSFTNGP10.phx.gbl>
| <AE**************@cpmsftngxa06.phx.gbl>
| | 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: gr**********@google.com
| | NNTP-Posting-Date: 6 Aug 2003 14:30:02 GMT
| | Path:
|
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.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!tdsn et-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
| |
| | v-*****@online.microsoft.com (Jeffrey Tan[MSFT]) wrote in message
| news:<AE**************@cpmsftngxa06.phx.gbl>...
| | > 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" <va***@diebold.com>
| | > | From: "Ken Varn" <va***@diebold.com>
| | > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| | > <sq**************@cpmsftngxa06.phx.gbl>
| | > <eL**************@tk2msftngp13.phx.gbl>
| | > <8$**************@cpmsftngxa06.phx.gbl>
| | > | 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: <#z*************@TK2MSFTNGP10.phx.gbl>
| | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | NNTP-Posting-Host: 204.151.249.23
| | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.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.
| | > | va***@diebold.com
| | > | -----------------------------------
| | > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| | > | news:8$**************@cpmsftngxa06.phx.gbl...
| | > | >
| | > | > 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" <va***@diebold.com>
| | > | > | From: "Ken Varn" <va***@diebold.com>
| | > | > | References: <#w**************@TK2MSFTNGP11.phx.gbl>
| | > <sq**************@cpmsftngxa06.phx.gbl>
| | > | > | 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: <eL**************@tk2msftngp13.phx.gbl>
| | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | > | NNTP-Posting-Host: 204.151.249.23
| | > | > | Path:
| cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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.
| | > | > | va***@diebold.com
| | > | > | -----------------------------------
| | > | > | "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in
| message
| | > | > | news:sq**************@cpmsftngxa06.phx.gbl...
| | > | > | >
| | > | > | > 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" <va***@diebold.com>
| | > | > | > | From: "Ken Varn" <va***@diebold.com>
| | > | > | > | 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: <#w**************@TK2MSFTNGP11.phx.gbl>
| | > | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| | > | > | > | NNTP-Posting-Host: 204.151.249.23
| | > | > | > | Path:
| | > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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.
| | > | > | > | va***@diebold.com
| | > | > | > | -----------------------------------
| | > | > | > |
| | > | > | > |
| | > | > | > |
| | > | > | >
| | > | > |
| | > | > |
| | > | > |
| | > | >
| | > |
| | > |
| | > |
| |
|
|

Nov 15 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.