如果從 Microsoft 的代碼中拋出異常,我如何找出最初導致異常的原因? (How do I find out what originally caused an exception, if it gets thrown from Microsoft's code?)


問題描述

如果從 Microsoft 的代碼中拋出異常,我如何找出最初導致異常的原因? (How do I find out what originally caused an exception, if it gets thrown from Microsoft's code?)

I have two controls containing DataGridViews on different panes in a DockPanel.  If one is in edit mode and I switch pane, I get a NullReferenceException thrown from within the DataGridView's EndEdit() method.  The stack trace doesn't go any deeper than that and the exception doesn't contain any more information.

I've looked at that method in the reflector, and I can't see anything obviously null.  I suspect that the problem is actually in my code, but the exception is being rethrown from within Microsoft's code and that's resetting the stack trace.   How do I find out what originally caused the exception?


參考解法

方法 1:

If you suspect a bug in the MS code, you could download the debugging symbols from the symbol server, load them and trace it through at debug? Like so.

Note that the symbols are subject to one of the various licences. This may impact you if (for example) you work on "mono" contributions etc.

方法 2:

Have you looked into the InnerException property?

方法 3:

Follow the instructions to set up MS symbol server and source server1. Set the debugger to break on NullReferenceException being thrown. Then either you will get full source code for debugging, or at least a complete stack trace.

1 Note, the QFE listed is included in SP1.

(by SimonMarc GravellsteffenjRichard)

參考文件

  1. How do I find out what originally caused an exception, if it gets thrown from Microsoft's code? (CC BY-SA 3.0/4.0)

#dockpanel #datagridview #Exception #.net #C#






相關問題

為什麼 DockPanel.Dock="Bottom" 將元素放在頂部? (Why does DockPanel.Dock="Bottom" put element at the top?)

在 DevExpress 停靠面板中調整內容大小 (Resizing contents inside DevExpress Docking Panels)

DockPanel LastChildFill 調整為 MinWidth? (DockPanel LastChildFill resizing to MinWidth?)

如何更改 DockWindow 上 TitleBar 的背景色? (How to change the Backcolor of TitleBar on DockWindow?)

WPF:HorizontalAlignment=Stretch、MaxWidth 和 Right 同時對齊? (WPF: HorizontalAlignment=Stretch, MaxWidth, and Right aligned at the same time?)

如何使 DockPanel 中的項目擴展以適應 WPF 中的所有可用空間? (How to make items in a DockPanel expand to fit all available space in WPF?)

AvalonDock 的狀態和狀態,AvalonDock 的選項 (State and status of AvalonDock, options to AvalonDock)

如何讓唯一的 DockPanel 子元素停靠在頂部 (How to get sole DockPanel child element to dock on the top)

如果從 Microsoft 的代碼中拋出異常,我如何找出最初導致異常的原因? (How do I find out what originally caused an exception, if it gets thrown from Microsoft's code?)

WPF 拖放面板(如 iGoogle、BBC 網站、blacklight) (WPF Drag Drop Panel (like iGoogle, BBC website, blacklight))

如何使 WPF 文本框填充兩個按鈕之間的所有可用空間? (How to make a WPF TextBox fill all available space between two buttons ?)

DockPanel 不可見,即使它設置為可見 (DockPanel is not visible even though it is set to visible)







留言討論