考虑下面的C#代码:为什么RuntimeMethodInfo.Invoke不显示在我的Visual Studio调试器callstack上?
class Program
{
static public void Print(string toPrint)
{
Console.WriteLine(toPrint);
}
static void Main(string[] args)
{
Type program = typeof(Program);
MethodInfo methodInfo = program.GetMethod("Print", BindingFlags.Static | BindingFlags.Public);
methodInfo.Invoke(null, new object[] { "a" });
}
}
当我在使用Visual 运行工作室 2008或Visual 工作室 2008年,打一个断点,我把“打印”方法中,我得到了以下调用堆栈窗口:
ConsoleApplication4.exe ConsoleApplication4.Program.Print(字符串 toPrint)
[原产于托管陈德良sition]
[托管到本机过渡]
ConsoleApplication4.exe!ConsoleApplication4.Program.Main(字符串[] 参数)
为什么不RuntimeMethodInfo.Invoke
在我的调用堆栈显示?毕竟,这是一种管理方法,所以为什么我没有看到它,因为我期望?
此外,一般来说,这里的规则是什么?我可能希望从我的调用堆中丢失哪些托管方法?
很抱歉,但你是什么意思正是由“化解下调至”? “Invoke”和“InvokeMethodFast”没有标记为MethodImplOptions.InternalCall,只有“_InvokeMethodFast”是:我可以在Reflector中看到它们的代码。 –
@Omer通过我的意思是'_InvokeMethodFast'最终将被调用。 “Invoke”和“_InvokeMethodFast”之间的所有内容都是“DebuggerHidden”,并且可能因为“Just My Code”被启用而被排除。我更新了我的答案,以获得更完整的调用堆栈 – JaredPar
- 根据[此博客文章总结了DebuggerXAttributes的效果](http://blogs.msdn.com/b/stevejs/archive/2005/12 /03/499803.aspx)和我自己的测试,不管“Just My Code”是什么,DebuggerHidden方法都不会显示在callstack上。 –