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

StackFrame is inconsistent in Debug version and Release version

P: n/a
Hi all,

I have a small piece of code to use StackFrame to GetMethod, I found it is
inconsistent in Debug version and Release version, is there anything I am
doing wrong?
Here is code, build in Debug and Release version, you will get different
results.
My env. is VS 2005 on XP with SP2.

Thanks in advanced.

HCF
---------------------------------------------------

using System;
using System.Diagnostics;
using System.Reflection;

class Example
{
private static string GenerateFuncName()
{
StackFrame sf = new StackFrame(2);
MethodBase mb = sf.GetMethod();
if ( mb != null )
return mb.DeclaringType.Name + "." + mb.Name;
else
return "Unknown FuncName";
}

private static string getInfo()
{
string info = GenerateFuncName();
return info;
}

static void Main()
{
Console.WriteLine(getInfo());
return;
}
}
May 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"HCF_15" <hc****@hotmail.com> wrote:
I have a small piece of code to use StackFrame to GetMethod, I found it is
inconsistent in Debug version and Release version, is there anything I am
doing wrong?


Debug mode inhibits CLR optimizations. One CLR optimization inhibited is
inlining. What you are seeing is the result of method inlining.

From the StackFrame documentation (I know, it's a different class):

---8<---
StackTrace might not report as many method calls as expected, due to
code transformations that occur during optimization.
--->8---

-- Barry
May 15 '06 #2

P: n/a
Got it, Thanks Barry.

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:6h********************************@4ax.com...
"HCF_15" <hc****@hotmail.com> wrote:
I have a small piece of code to use StackFrame to GetMethod, I found it
is
inconsistent in Debug version and Release version, is there anything I am
doing wrong?


Debug mode inhibits CLR optimizations. One CLR optimization inhibited is
inlining. What you are seeing is the result of method inlining.

From the StackFrame documentation (I know, it's a different class):

---8<---
StackTrace might not report as many method calls as expected, due to
code transformations that occur during optimization.
--->8---

-- Barry

May 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.