2012-02-10 82 views
1

我在計算出發生在我的應用程序中的異常時遇到了困難。PresentationFramework.dll中的System.NullReference異常的一次機會異常?

基本上,我主持了一個wpf用戶控件,它裏面有一個infragistics XamDataGrid。

當我關閉應用程序,我收到類型的異常的無限循環:

線程「」(0x24020)已退出,代碼爲0(爲0x0)。 PresentationFramework.dll中發生類型'System.NullReferenceException'的第一次機會異常 PresentationFramework.dll中發生了類型'System.NullReferenceException'的第一次機會異常 PresentationFramework中發生了類型'System.NullReferenceException'的第一次機會異常。 dll的
等等....

如果我刪除XAMDATAGRID,一切工作正常...所以即時猜測它的問題與電網...

堆棧跟蹤的部分是: (林不知道這是否有幫助:)

------------------------------------------------- ------------------------------------------ PresentationFramework.dll!System.Windows。 DeferredAppResourceReference.GetValue(System.Windows.BaseValueSourceInternal valueSource =繼承)+送出0x4d字節

WindowsBase.dll中!System.Windows.DependencyObject.GetEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex},System.Windows .DependencyProperty DP = {System.Windows.DependencyProperty},System.Windows.RequestFlags請求)+ 0xe6字節

WindowsBase.dll中!System.Windows.DependencyObject.GetValueEntry(System.Windows.EntryIndex entryIndex,System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty},System.Windows.PropertyMetadata metadata = {System.Windows.Fra meworkPropertyMetadata},System.Windows.RequestFlags請求= FullyResolved)+ 0x2fe字節

WindowsBase.dll中!System.Windows.DependencyObject.GetValue(System.Windows.DependencyProperty DP)+ 0x48字節 PresentationFramework.dll!MS.Internal。 Text.TextProperties.InitCommon(System.Windows.DependencyObject target = {System.Windows.Controls.TextBlock})+ 0x6b bytes PresentationFramework.dll!MS.Internal.Text.TextProperties.TextProperties(System.Windows.FrameworkElement target = {System .Windows.Controls.TextBlock},bool isTypographyDefaultValue = true)+ 0x42 bytes
PresentationFramework.dll!System.Windows.Controls.TextBlock.GetLineProperties()+ 0x37 bytes
PresentationFramework.dll!System .Windows.Controls.TextBlock.EnsureTextBlockCache()+ 0x2f bytes PresentationFramework.dll!System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size constraint)+ 0x50 bytes
PresentationFramework.dll!System.Windows.FrameworkElement。 MeasureCore(System.Windows.Size availableSize)+ 0x1ee bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)+ 0x249 bytes
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild( System.Windows.UIElement元素,System.Windows.Size約束)+ 0xfe字節
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size約束)+ 0x18字節 PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows。SizeSize available)+ 0x1ee bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)+ 0x249 bytes
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows。大小約束)+ 0x10c字節 PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)+ 0x1ee bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x249 bytes
PresentationFramework.dll!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size constraint)+ 0x187 bytes
PresentationFramework.dll!System.Windows.FrameworkEleme nt.MeasureCore(System.Windows.Size availableSize)+ 0x1ee bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)+ 0x249 bytes
PresentationFramework.dll!System.Windows.Controls。 Grid.MeasureOverride(System.Windows.Size約束)+ 0x1cf字節


如何去解決任何幫助,這是非常感謝!謝謝!

+0

如何把代碼放在你實例化你正在使用的網格的地方..你是否還在項目級添加了一個引用..除了使用...? – MethodMan 2012-02-10 16:43:55

+0

嗨,我是一個新手到wpf,所以我道歉,如果我不清楚....它只是一個簡單的XamDataGrid ...我將它實例化爲Xamdatagrid網格=新Xamdatagrid(); grid.Datasource = mysource;然後我將它作爲sp.Children.Add(grid)添加到StackPanel。這個回答有問題嗎?謝謝! – user1202434 2012-02-10 16:47:36

+0

然後我們可以看到一些代碼..它可能只是幫助 – MethodMan 2012-02-10 16:48:16

回答

1

發生此錯誤的原因是,當Winforms應用程序關閉時,WPF調度程序線程尚未完成對事件消息的待處理隊列的刷新。當它開始這樣做時,應用程序對象已經關閉並被清除。要解決,就在託管窗口關閉之前,只需在WPF消息循環中調用關閉。

Application.Current.Dispatcher.InvokeShutdown() 
+0

謝謝@ outro56。這真的節省了我的時間。偉大的:) – 2017-02-25 17:49:54