StackFrame is inconsistent in Debug version and Release version

H

HCF_15

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;
}
}
 
B

Barry Kelly

HCF_15 said:
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
 
H

HCF_15

Got it, Thanks Barry.

Barry Kelly said:
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
 

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