簡體   English   中英

來自不同窗口的ShowDialog中的異常

[英]Exception in ShowDialog from different Window

當發生未處理的異常時,我要顯示一個自定義窗口。 像這樣:

private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    try
    {
        e.Handled = true; // If e.Handled == false or error dialog will not show.
        string errorMassage = ExceptionFormatter.FormatException(e.Exception)
        var window = new FatalErrorWindow(errorMassage );
        window.ShowDialog();
    }
    catch (Exception ex)
    {
        MessageBox.Show(errorMassage, "Program error", MessageBoxButton.OK);            
    }
    Application.Current.Shutdown(-1);
}

在某些情況下,ShowDialog本身會引發異常,因此我為此添加了一個try / catch,並發現在調用ShowDialog時,.NET似乎為另一個窗口 (假定是主窗口?)執行了完整的UpdateLayout周期

現在的問題是,如果該循環在“測量/排列”階段拋出異常,則基本上無法正常處理。 任何試圖顯示漂亮對話框的嘗試都會遇到相同的異常。

有人建議如何解決/解決這個問題嗎? ¨

編輯:( 回應評論)

我擔心的是,我無法嘗試/抓住任何東西來防止這種情況。 在應用程序完全不相關的部分中,任何UI元素(即我本人,第三方或什至是.NET元素)都可以在Measure / Arrange方法中引發NullReferenceException,並且它本質上是不可捕獲的。

下面是說明問題的堆棧跟蹤。

在3rdPartyVendor.UI.Xaml.Grid.GridDataRow.UpdateFixedRowState()
在3rdPartyVendor.UI.Xaml.Grid.RowGenerator.EnsureRows(VisibleLinesCollection visibleRows)在3rdPartyVendor.UI.Xaml.Grid.VisualContainer.EnsureItems(Boolean sureColumns)在3rdPartyVendor.UI.Xaml.Grid.VisualContainer.MeasureOverride(Size) .Windows.FrameworkElement.MeasureCore(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中的System.Windows.Controls.ScrollContentPresenter.MeasureOverride(大小約束)位於f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Primitives \\ ScrollContentPresenter.cs:line 432 )在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.ScrollViewer.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ScrollViewer.cs:line 1220在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在System.Windows.Controls.Border.MeasureOverride(Size約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Border.cs:line 245
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在3rdPartyVendor.UI.Xaml.Grid.SfDataGrid.MeasureOverride(Size availableSize)在System.Windows.FrameworkElement.MeasureCore(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在XXXXXX.Common.Controls.CachingPanel.MeasureOverride(Size availableSize)在F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Common \\ Controls \\ CachingPanel.cs:line 84
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在System.Windows.Controls.Border.MeasureOverride(Size約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Border.cs:line 245
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在System.Windows.UIElement.Measure(Size availableSize)在System.Windows.Controls.Border.MeasureOverride(Size約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Border.cs:line 245
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在XXXXXX.Common.Controls.CachingPanel.MeasureOverride(Size availableSize)在F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Common \\ Controls \\ CachingPanel.cs:line 84
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在XXXXXX.Common.Controls.CachingPanel.MeasureOverride(Size availableSize)在F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Common \\ Controls \\ CachingPanel.cs:line 84
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在System.Windows.Controls.Border.MeasureOverride(Size約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Border.cs:line 245
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Control.cs:line 711的System.Windows.Controls.Control.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(大小availableSize)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(可用大小大小)在System.Windows.Controls.Grid.MeasureOverride(大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 441在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UI.UIElement.Measure(Size availableSize)在System.Windows.Controls.Grid.MeasureCell(Int32 cell,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs :第1431行
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV,Boolean&hasDesiredSizeUChanged)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1286中
在System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,Size referenceSize,Boolean ignoreDesiredSizeU,Boolean forceInfinityV)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 1250中
在System.Windows.FrameworkElement.MeasureCore的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Grid.cs:line 701的System.Windows.Controls.Grid.MeasureOverride(大小約束)處(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:行4402
在System.Windows.UIElement.Measure(Size availableSize)在MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ MS \\ Internal \\ Helper.cs:第547行System.Windows.FrameworkElement.MeasureCore中f。\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ ContentPresenter.cs:line 495行的System.Windows.Controls.ContentPresenter.MeasureOverride(大小約束) f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Documents \\ AdornerDecorator.cs:line 129的System.Windows.Documents.AdornerDecorator.MeasureOverride(大小約束)處的System.Windows.UIElement.Measure(Size availableSize)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.UIElement.Measure(Size availableSize)在System.Windows.Controls.Border.MeasureOverride(Size約束)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Controls \\ Border.cs:line 245
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4402中的System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在System.Windows.Window.Window.MeasureOverrideHelper(大小約束)在System.Windows.UIElement.Measure(大小availableSize)在System.Windows的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:line 3497 f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:line 1881中的.Window.MeasureOverride(Size availableSize)在f:\\ dd \\ wpf \\中的System.Windows.FrameworkElement.MeasureCore(Size availableSize) src \\ Framework \\ System \\ Windows \\ FrameworkElement.cs:line 4323
在System.Windows.UIElement.Measure(在System.Windows.ContextLayoutManager.UpdateLayout() 在System.Windows.UIElement.UpdateLayout()在System.Windows.Interop.HwndSource.SetLayoutSize()在System.Windows.Interop System.Windows.Interop.HwndSource.set_RootVisual(可視值)處的.HwndSource.set_RootVisualInternal(可視值)
在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:的 System.Windows.Window.SetRootVisual()處,在f:\\ dd \\ wpf \\的System.Windows.Window.SetRootVisualAndUpdateSTC() src \\ Framework \\ System \\ Windows \\ Window.cs:System.Windows.Window.SetupInitialState中的第2978行(f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows中的DoubleRequestTop,Double requestLeft,Double requestWidth,Double requestHeight) \\ System.Windows.Window.CreateSourceWindow處的\\ Window.cs:line 2942(ShowShow中的布爾值),f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:System.Windows.Window.CreateSourceWindowDuringShow處的2679行)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window中System.Windows.Window.SafeCreateWindowDuringShow()中的f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:line 2532 .cs:line 5643在System.Windows.Window.ShowHelper(Object booleanBox)在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:Line 5743在System.Windows.Window.Show()在f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs: System.Windows的 214行 f:\\ dd \\ wpf \\ src \\ Framework \\ System \\ Windows \\ Window.cs:line 516在XXXXXX.Common.Controls.MultiButtonDialog.ShowOK中的.Window.ShowDialog()(F:\\ git中的對象內容,字符串標題) \\ XXXXXXX \\ Source \\ XXXXXX.Common \\ Dialogs \\ MultiButtonDialog.xaml.cs:第55行位於XXXXXX.Wpf.VelocityErrorHandler。<> c__DisplayClass17_0.b__0()在F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Wpf \\ VelocityFatalErrorHandler.cs :F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Wpf \\ WpfDispatcher.cs中XXXXXX.Wpf.WpfDispatcher.Invoke(Action action)的第216行:DFDS.Freight.Common.Core.DispatchContext.Invoke(Action action)的第32行)的F:\\ git \\ XXXXXXX \\ Source \\ DFDS.Freight.Common.Portable \\ Core \\ IDispatchContext.cs:第30行在XXXXXX.Wpf.VelocityErrorHandler.HandleFatalException(Exception exception)in F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX .Wpf \\ VelocityFatalErrorHandler.cs:第206行位於XXXXXX.Wpf.VelocityErrorHandler.HandleAnyException(Exception exception,Boolean isUnhandledTaskException)位於F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Wpf \\ VelocityFatalErrorHandler.cs:第XXXXXX.Wpf.Veloci行 F:\\ git \\ XXXXXXX \\ Source \\ XXXXXX.Wpf \\ VelocityFatalErrorHandler.cs:第29行在XXXXXX.Wpf.ApplicationInitializer.OnDispatcherUnhandledException(Object sender,DispatcherUnhandledExceptionExceptionEventArgs e)中的tyErrorHandler.HandleUnhandledException(Exception exception,Boolean isUnhandledTaskException): \\ XXXXXXX \\ Source \\ XXXXXX.Wpf \\ ApplicationInitializer.cs:第605行
在System.Windows.Threading.Dispatcher.CatchException(Exception e)
System.Windows.Threading.ExceptionWrapper.TryCatchWhen(對象來源,System.Windows.Threading.ExceptionWrapper.CatchException(對象來源,Exception e,委托catchHandler)處System.Windows.Threading.Dispatcher.CatchExceptionStatic(對象來源,Exception e,委托catchHandler) ,在System.Windows.Threading.DispatcherOperation.InvokeImpl()在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)在MS.Internal.CulturePreservingExecutionContext.Object.CallbackWrapper(Object )在System.Threading.ExecutionContext.Run()處位於System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallback回調,對象狀態,布爾serveSyncCtx)。在MS.Internal.CulturePreser中運行(ExecutionContext executeContext,ContextCallback回調,對象狀態) vingExecutionContext.Run(CulturePreservingExecutionContext executeContext,ContextCallback回調,對象狀態)在System.Windows.Threading.Dispatcher.ProcessQueue()在System.Windows.Threading.Dispatcher.ProcessQueue()在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd ,位於MS.Win32.HwndWrapper.WndProc的Int32 msg,IntPtr wParam,IntPtr lParam,布爾值和已處理)(位於MS.Win32.Hwndbackclassper。 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(對象源,委托回調,對象args,Int32 numArgs,委托catchHandler的System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回調,對象args,Int32 numArgs)

我相信您的解決方案實際上是最好的。 當您最終DispatcherUnhandledException事件處理程序時,將無法保證穩定狀態。 例如,如果您的異常是從WPF內部引發的,則您可能無法綁定屬性。 您的錯誤消息對話框將為空白。

您可以在下面找到針對該特定問題的修復程序。

private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    var errorMassage = ExceptionFormatter.FormatException(e.Exception)

    try
    {            
        // When the WPF framework throws, our error dialog will have problem binding data.
        // In this case, we must revert to an oldschool message dialog in order to see
        // the actual error message!
        var isFrameworkError = ex.Source?.Equals("PresentationFramework") == true;
        if (isFrameworkError)
        {
            MessageBox.Show(errorMassage, "Program error", MessageBoxButton.OK);
        }
        else
        {
            var window = new FatalErrorWindow(errorMassage );
            window.ShowDialog();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(errorMassage, "Program error", MessageBoxButton.OK);
    }

    Application.Current.Shutdown(-1);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM