[英]Why doesn't RuntimeMethodInfo.Invoke show up on my Visual Studio debugger callstack?
Consider the following C# code:考虑以下 C# 代码:
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" });
}
}
When I run it in either Visual Studio 2008 or Visual Studio 2008 and hit a breakpoint I put inside the "Print" method, I get the following in the callstack window:当我在 Visual Studio 2008 或 Visual Studio 2008 中运行它并遇到我在“打印”方法中放置的断点时,我在调用堆栈 window 中得到以下信息:
ConsoleApplication4.exe.ConsoleApplication4.Program.Print(string toPrint)
ConsoleApplication4.exe.ConsoleApplication4.Program.Print(字符串到打印)
[Native to Managed Transition]
[本机到托管转换]
[Managed to Native Transition]
[管理到本地转换]
ConsoleApplication4.exe.ConsoleApplication4.Program.Main(string[] args)
ConsoleApplication4.exe.ConsoleApplication4.Program.Main(string[] args)
Why doesn't RuntimeMethodInfo.Invoke
show up in my callstack?为什么
RuntimeMethodInfo.Invoke
没有出现在我的调用堆栈中? It is a managed method, after all, so why don't I see it as I would expect?毕竟,它是一种托管方法,那么为什么我看不到我所期望的呢?
Also, in general, what are the rules here?另外,一般来说,这里的规则是什么? Which managed methods can I expect to be missing from my callstack?
我的调用堆栈中可能会缺少哪些托管方法?
The reason is that the method isn't actually a managed method.原因是该方法实际上不是托管方法。
RunTimeMethodInfo.Invoke
will eventually resolve down to RuntimeMethodHandle._InvokeMethodFast
which is marked as an MethodImplOptions.InternalCall
. RunTimeMethodInfo.Invoke
最终将解析为RuntimeMethodHandle._InvokeMethodFast
,它被标记为MethodImplOptions.InternalCall
。 This means the call is actually implemented as a helper directly in the CLR .这意味着调用实际上是直接在CLR中作为帮助程序实现的。
In terms of general rules for what won't show up in your call stack:关于不会出现在调用堆栈中的一般规则:
Just My Code
enabled (which is the default) pretty much anything you didn't write will show up as [External Code]
on the call stack.Just My Code
(这是默认设置),那么您未编写的几乎所有内容都会在调用堆栈上显示为[External Code]
。Native to Managed
and Managed to Native
transitions on the call stack.Native to Managed
和Managed to Native
的转换。DebuggerHidden
, especially when combined with 'just my code' methods, but I wouldn't necessary expect them to show up on the call stack.DebuggerHidden
的确切规则,尤其是与“仅我的代码”方法结合使用时,但我不必期望它们出现在调用堆栈上。 If you want to see the raw call stack in all of its glory then you'll need to do the following.如果您想看到原始调用堆栈的所有荣耀,那么您需要执行以下操作。
Just My Code
Just My Code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.