如何从 C# 读取堆栈跟踪,如我的示例
本文关键字:我的 跟踪 堆栈 读取 | 更新日期: 2023-09-27 18:30:29
如何读取此堆栈跟踪?谁能解释我如何理解这一点以修复错误。
"Frame Image Function Offset
0 coredll.dll xxx_RaiseException 19
1 mscoree3_7.dll 436488
2 mscoree3_7.dll 386545
3 mscoree3_7.dll 540936
4 TransitionStub 0
5 GeoCaching.Main.btnGoToPin_Click 312
6 System.Windows.Controls.Primitives.ButtonBase.OnClick 132
7 System.Windows.Controls.Button.OnClick 120
8 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp 228
9 System.Windows.Controls.Control.OnMouseLeftButtonUp 100
10 MS.Internal.JoltHelper.FireEvent 896
11 mscoree3_7.dll 429164
12 mscoree3_7.dll 430528
13 mscoree3_7.dll 610803
14 mscoree3_7.dll 374593
15 0
16 agcore.dll CCoreServices::CLR_FireEvent 385
17 npctrl.dll CControlBase::ScriptCallback 435
18 npctrl.dll CXcpDispatcher::OnScriptCallback 547
19 npctrl.dll CXcpDispatcher::OnReentrancyProtectedWindowMessage 479"
您不会从该堆栈跟踪中获得太多信息。可以读取Image
名称(即方法所在的程序集的名称)和Function
名称(方法是方法的名称)。
看起来 GeoCaching.Main.btnGoToPin_Click
或 TransitionStub
方法中存在异常,但堆栈跟踪本身并不能告诉您哪种异常,或者 Exception 对象中放置了哪些信息。
如果已使用调试信息编译应用程序,则会在堆栈跟踪中获得更多信息,例如每个方法中的行号。
从提供的信息来看,您只能在btnGoToPin_Click
中遇到异常。
要查看它的真正来源,请在该事件处理程序中添加一个try/catch
,并且很可能会发现错误。
祝你好运
如前所述,错误在btnGoToPin_Click的某个地方但是应用程序是在发布模式下编译的,这就是您没有完整堆栈跟踪的原因。
在发布模式下编译应用时,编译器会进行多项优化。第一个可能适用于您的情况是用此方法的主体替换对小方法的调用。这称为"内联优化"
因此,也许您的错误在 btnGoToPin_Click 中调用的另一个方法中,但由于内联而对堆栈跟踪不可见。
如果您想了解有关内联的更多信息,这里有一篇不错的文章