![](/img/trans.png)
[英]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?
[英]Why doesn't RuntimeMethodInfo.Invoke show up on my Visual Studio debugger callstack?
考慮以下 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" });
}
}
當我在 Visual Studio 2008 或 Visual Studio 2008 中運行它並遇到我在“打印”方法中放置的斷點時,我在調用堆棧 window 中得到以下信息:
ConsoleApplication4.exe.ConsoleApplication4.Program.Print(字符串到打印)
[本機到托管轉換]
[管理到本地轉換]
ConsoleApplication4.exe.ConsoleApplication4.Program.Main(string[] args)
為什么RuntimeMethodInfo.Invoke
沒有出現在我的調用堆棧中? 畢竟,它是一種托管方法,那么為什么我看不到我所期望的呢?
另外,一般來說,這里的規則是什么? 我的調用堆棧中可能會缺少哪些托管方法?
原因是該方法實際上不是托管方法。 RunTimeMethodInfo.Invoke
最終將解析為RuntimeMethodHandle._InvokeMethodFast
,它被標記為MethodImplOptions.InternalCall
。 這意味着調用實際上是直接在CLR中作為幫助程序實現的。
關於不會出現在調用堆棧中的一般規則:
Just My Code
(這是默認設置),那么您未編寫的幾乎所有內容都會在調用堆棧上顯示為[External Code]
。Native to Managed
和Managed to Native
的轉換。DebuggerHidden
的確切規則,尤其是與“僅我的代碼”方法結合使用時,但我不必期望它們出現在調用堆棧上。如果您想看到原始調用堆棧的所有榮耀,那么您需要執行以下操作。
Just My Code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.