Reputation: 2273
I am having trouble figuring out an exception that occurs in my application.
Basically, I am hosting a wpf user control which has an infragistics XamDataGrid in it.
When I close the application, I am getting an infinite loop of exceptions of type:
The thread '' (0x24020) has exited with code 0 (0x0).
A first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll
A first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll
A first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll
and so on....
If I REMOVE THE XAMDATAGRID, everything works fine...so im guessing its an issue with the grid...
A part of the stack trace is: (Im not sure if this is helpful:)
------------------------------------------------------------------------------------------- PresentationFramework.dll!System.Windows.DeferredAppResourceReference.GetValue(System.Windows.BaseValueSourceInternal valueSource = Inherited) + 0x4d bytes
WindowsBase.dll!System.Windows.DependencyObject.GetEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.RequestFlags requests) + 0xe6 bytes
WindowsBase.dll!System.Windows.DependencyObject.GetValueEntry(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata metadata = {System.Windows.FrameworkPropertyMetadata}, System.Windows.RequestFlags requests = FullyResolved) + 0x2fe bytes
WindowsBase.dll!System.Windows.DependencyObject.GetValue(System.Windows.DependencyProperty dp) + 0x48 bytes
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 element, System.Windows.Size constraint) + 0xfe bytes
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint) + 0x18 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!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint) + 0x10c 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!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size constraint) + 0x187 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!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x1cf bytes
Any help on how to go about solving this is really appreciated! Thank you!
Upvotes: 1
Views: 3034
Reputation: 62
The error occurs because when the winforms application shuts down, the WPF dispatcher thread has not finished flushing it pending queue for event messages. When it gets around to doing so, the application object has already been closed and nulled out. To resolve, right before the hosting window is closed, just invoke shutdown on the WPF message loop.
Application.Current.Dispatcher.InvokeShutdown()
Upvotes: 1