0
votes

I have an application that displays a few datagrids in the tabitems of a TabControl. On one of the machines on which it's deployed - and only one - switching tabs crashes the application without any warning. I have no way to debug the app on that machine. The only indication I have on the crash comes from the event viewer. Here's the exception stack trace:

Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack: at System.Windows.Controls.Primitives.DataGridColumnHeader.SetLeftGripperVisibility() at System.Windows.Controls.Primitives.DataGridColumnHeader.HookupGripperEvents() at System.Windows.FrameworkElement.ApplyTemplate() at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.DataGridCellsPanel.MeasureChild(System.Windows.UIElement, System.Windows.Size) at System.Windows.Controls.DataGridCellsPanel.GenerateChild(System.Windows.Controls.Primitives.IItemContainerGenerator, System.Windows.Size, System.Windows.Controls.DataGridColumn, Int32 ByRef, System.Windows.Size ByRef) at System.Windows.Controls.DataGridCellsPanel.GenerateChild(System.Windows.Controls.Primitives.IItemContainerGenerator, System.Windows.Size, System.Windows.Controls.DataGridColumn, System.IDisposable ByRef, Int32 ByRef, System.Windows.Size ByRef)
at System.Windows.Controls.DataGridCellsPanel.DetermineRealizedColumnsBlockList(System.Windows.Size) at System.Windows.Controls.DataGridCellsPanel.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.ContextLayoutManager.UpdateLayout() at System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object) at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object) at System.Windows.Media.MediaContext.RenderMessageHandler(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.ExecutionContext.runTryCode(System.Object) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run() at MyApp.App.Main()

It all happens in external code. I tries to inherit from DataGrid, override the ApplyTemplate method and putting a try catch in it. But it seems this is not allowed and the resulting control is unusable. Any suggestions on how to fix this? Thank you

1

1 Answers

0
votes

It looks like a bug and you should contact microsoft support team. but there's another option you can give it a try.

Here you can find the beta version of DataGridColumnHeader source code.

Edit

According to that source code my guess is if you turn off the column resize or anything related to column header's "Grip" area it might no longer throw the exception.