473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reflection, StackTrace, and Release Builds

I'm trying to write a function that can reliably know the name of the
calling method. I've figured out how to do this:

string methodname = (new StackTrace()).GetFrame(1).GetMethod().Name;

This seems to get the name of the method that called the current
method. But there are two problems. One is that I have to hardcode
one step back in the stack. When switching to a release build, this
may not work corerctly because of optimization. The other, more
serious problem is that the method name is stripped from release
buildes.

Is there a way, like with an attribute for example, to force the
compiler not to inline certain functions?

Also, clearly reflection has to work in release builds. So it's
possible in a release build to know the name of a method in a class.
It's also possible to get the stack frame, but without the name
property filled in. Is there a way to correlate the two? Some kind of
handle that is set in the release build stack frame that can be
compared to something in reflection so I can get the name, like a
bridge between the stack frame and reflection?

One of the requirements of what I'm doing is that they want tracing and
performance monitoring to be as unobtrusive as possible while still
working with release builds in production.

tia, brian

Nov 17 '05 #1
2 4296
I'm trying to write a function that can reliably know the name of the
calling method.
The most reliable way is still to pass it in as a parameter.

Is there a way, like with an attribute for example, to force the
compiler not to inline certain functions?
Yes:

using System.Runtime.CompilerServices;
....
[MethodImpl(MethodImplOptions.NoInlining)]

Is there a way to correlate the two?


I doubt it. If there was, it would probably already have been taken
care of.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
>I doubt it. If there was, it would probably already have been taken
care of.


Before, I was relying on the information in msdn. So I assumed that it
was correct when it said that GetMethod().Name wouldn't work in release
builds.

So I tried this:

private void Form1_Load(object sender, System.EventArgs e)
{
one();
}

private void one()
{
StackTrace st = new StackTrace();
StackFrame sf = st.GetFrame(1);
MessageBox.Show(sf.GetMethod().Name);
}

.... to verify that it was in fact not working. As it turns out, it
works fine, even as a release build. This seems to contradict the msdn
and some other newsgroup posts I've seen.

I discovered that st.ToString() returns the entire stack frame, method
names and all, even in release mode. I was going to parse this string
when I discovered that Name works anyway. What's going on here? Was
this broken in the 1.0 frame work and now works in 1.1? Am I getting
lucky and sometimes it works sometimes not? Is there a compiler switch
somewhere that removes even more information? Whats going on?

brian

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
Since I need to dotfuscate my exe file anyway, does it make any difference if I use Debug or Release versions. Would a Debug version be easier to decompile/study/reverse engineer than a Release...
6
by: swartzbill2000 | last post by:
Hello, I have a VB 2005 Express project with a TraceListener-derived class to route Debug.Print output to a log file. It works fine for Debug builds. What is the correct combination of changes to...
1
by: TheSteph | last post by:
Hi, Does anybody know what's the difference between the "Debug build" of a C# application and the "Release build" ? In my case, both are 774.144 bytes, and both seems to have the same
5
by: B. | last post by:
We just recently move to code from VC++6 to VC++.NET 2005 and upgrade the warning level from 3 to 4. In debug mode, we compile the application with no warning no error, but when I build it in...
0
by: Sutabi | last post by:
I'm trying to compile a "Release" build of a project, and in debug more it compiles and runs fine. In release mode it builds, but does not run and returns this exception. I have no idea what this...
6
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++...
1
by: Daniel | last post by:
do release builds have the same amount of info in exceptions? e.g. will exceptions cought in release builds contain stack trace etc.?
3
by: Bob Johnson | last post by:
It is my understanding - and please correct me if I'm wrong - that when building a project in debug mode, I can deploy the .pdb file along with the ..exe and thereby have access to the specific...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.