简体   繁体   English

为什么 RuntimeMethodInfo.Invoke 没有出现在我的 Visual Studio 调试器调用堆栈上?

[英]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:关于不会出现在调用堆栈中的一般规则:

  • If you have 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]
  • If you are debugging managed only then you'll probably end up seeing a lot of Native to Managed and Managed to Native transitions on the call stack.如果您只调试托管,那么您可能最终会在调用堆栈上看到很多本Native to ManagedManaged to Native的转换。
  • When dealing with internally implemented methods, you'll also see a bit of fuzziness on the call stack.在处理内部实现的方法时,您还会在调用堆栈上看到一些模糊性。
  • I'm not sure on the exact rules for 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.如果您想看到原始调用堆栈的所有荣耀,那么您需要执行以下操作。

  • Debug with both managed and native debugging enabled在启用托管和本机调试的情况下进行调试
  • Disable Just My Code禁用Just My Code

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的代码在调试器中引发异常时,为什么Visual Studio 2010不向我显示弹出窗口以及引发异常的位置? - Why doesn't Visual Studio 2010 show me a popup and the location where an exception is thrown when my code throws an exception in the debugger? Visual Studio 2017不会在调试器上显示工具提示 - Visual Studio 2017 doesn't show tooltip on debugger 为什么visual studio在应用程序退出时不退出调试器? - Why doesn't visual studio exit the debugger on application exit? 为什么我的GridView不显示? - Why doesn't my GridView show up? Visual Studio 2012调试器无法正常工作 - visual studio 2012 debugger doesn't work 当我在静态构造函数中发生异常时,为什么Visual Studio不显示异常消息? - Why doesn't Visual Studio show an exception message when my exception occurs in a static constructor? Visual Studio 2010-我的Windows窗体不会显示,除非我在之前或之后进行MessageBox.Show()调用 - Visual Studio 2010 - my Windows Form doesn't show up unless I make a MessageBox.Show() call before or after 为什么Visual Studio Debugger不会枚举BitArray并向我显示结果? - Why won't Visual Studio Debugger enumerate a BitArray and show me the results? 在 Visual Studio 2019 调试器中运行时,为什么控制台应用程序在最后一条语句后不退出? - Why doesn't console application exit after last statement when running in Visual Studio 2019 debugger? 为什么我的任务没有显示在Visual Studio的“任务”窗口中? - Why don't my Tasks show in the Visual Studio Tasks window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM