Description
We experience a rare crash when the selected item is changed in the datagrid that result in a NPE:
System.ArgumentNullException: Value cannot be null. Parameter name: item at System.Windows.Automation.Peers.DataGridCellItemAutomationPeer..ctor(Object item, DataGridColumn dataGridColumn) at System.Windows.Automation.Peers.DataGridItemAutomationPeer.GetOrCreateCellItemPeer(DataGridColumn column, Boolean addParentInfo) at System.Windows.Automation.Peers.DataGridAutomationPeer.GetCellItemPeer(DataGridCellInfo cellInfo) at System.Windows.Automation.Peers.DataGridAutomationPeer.RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) at System.Windows.Controls.DataGrid.OnSelectedCellsChanged(SelectedCellsChangedEventArgs e) at System.Windows.Controls.DataGrid.NotifySelectedCellsChanged() at System.Windows.Controls.DataGrid.ChangingSelectedCellsHelper.Dispose() at System.Windows.Controls.DataGrid.OnSelectionChanged(SelectionChangedEventArgs e) at System.Windows.Controls.Primitives.Selector.SelectionChanger.End() at System.Windows.Controls.Primitives.Selector.OnSelectedItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item) at System.Windows.Controls.SelectedItemCollection.InsertItem(Int32 index, Object item) at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Add(Object value)
or
System.ArgumentNullException: En værdi må ikke være null. Parameternavn: item ved System.Windows.Automation.Peers.DataGridCellItemAutomationPeer..ctor(Object item, DataGridColumn dataGridColumn) ved System.Windows.Automation.Peers.DataGridItemAutomationPeer.GetOrCreateCellItemPeer(DataGridColumn column, Boolean addParentInfo) ved System.Windows.Automation.Peers.DataGridAutomationPeer.GetCellItemPeer(DataGridCellInfo cellInfo) ved System.Windows.Automation.Peers.DataGridAutomationPeer.RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) ved System.Windows.Controls.DataGrid.OnSelectedCellsChanged(SelectedCellsChangedEventArgs e) ved System.Windows.Controls.DataGrid.NotifySelectedCellsChanged() ved System.Windows.Controls.DataGrid.ChangingSelectedCellsHelper.Dispose() ved System.Windows.Controls.DataGrid.AdjustPendingInfos() ved System.Windows.Controls.DataGrid.AdjustItemInfosAfterGeneratorChangeOverride() ved System.Windows.Controls.Primitives.Selector.AdjustNewContainers() ved System.Windows.Controls.Primitives.Selector.OnGeneratorStatusChanged(Object sender, EventArgs e) ved System.Windows.Controls.ItemContainerGenerator.SetStatus(GeneratorStatus value) ved System.Windows.Controls.ItemContainerGenerator.BatchGenerator.System.IDisposable.Dispose() ved System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure) ved System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) ved System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) ved System.Windows.FrameworkElement.MeasureCore(Size availableSize) ved System.Windows.UIElement.Measure(Size availableSize) ved System.Windows.ContextLayoutManager.UpdateLayout() ved System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) ved System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() ved System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) ved System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) ved System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) ved System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
The stacktrace might differ a bit from case-to-case but it always reaches OnSelectedCellsChanged(...) from which the road to the cell peer ctor is the same.
Reproduction Steps
None known. We have seen it across 12 different users over a period of 3 months.
Expected behavior
The client does not crash on a peer being created.
Actual behavior
The client crashes unexpectedly.
Regression?
Not that we know of.
Known Workarounds
We have just added a try-catch as an override on base.OnSelectedCellsChanged(...) but due to how rare the issue is, we have no way of knowing whether this solves the issues, or if it just leads to a bad state from which the client might/might not be able to continue.
Impact
Problem seems to be able to hit all users, regardless of them working on laptops, desktops, screen sizes, remote state and hardware acceleration.
Configuration
- .net framework 4.8
- Windows - newest version (over a 3-month period)
- x86
- Not confirmed
Other information
The datagrid we utilize is running with both sorting and filtering, so we have a lot of moving parts. In addition virtualization is also enabled, both horizontally and vertically since there might be a lot of columns, for a bunch of data.
Description
We experience a rare crash when the selected item is changed in the datagrid that result in a NPE:
System.ArgumentNullException: Value cannot be null. Parameter name: item at System.Windows.Automation.Peers.DataGridCellItemAutomationPeer..ctor(Object item, DataGridColumn dataGridColumn) at System.Windows.Automation.Peers.DataGridItemAutomationPeer.GetOrCreateCellItemPeer(DataGridColumn column, Boolean addParentInfo) at System.Windows.Automation.Peers.DataGridAutomationPeer.GetCellItemPeer(DataGridCellInfo cellInfo) at System.Windows.Automation.Peers.DataGridAutomationPeer.RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) at System.Windows.Controls.DataGrid.OnSelectedCellsChanged(SelectedCellsChangedEventArgs e) at System.Windows.Controls.DataGrid.NotifySelectedCellsChanged() at System.Windows.Controls.DataGrid.ChangingSelectedCellsHelper.Dispose() at System.Windows.Controls.DataGrid.OnSelectionChanged(SelectionChangedEventArgs e) at System.Windows.Controls.Primitives.Selector.SelectionChanger.End() at System.Windows.Controls.Primitives.Selector.OnSelectedItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item) at System.Windows.Controls.SelectedItemCollection.InsertItem(Int32 index, Object item) at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Add(Object value)or
System.ArgumentNullException: En værdi må ikke være null. Parameternavn: item ved System.Windows.Automation.Peers.DataGridCellItemAutomationPeer..ctor(Object item, DataGridColumn dataGridColumn) ved System.Windows.Automation.Peers.DataGridItemAutomationPeer.GetOrCreateCellItemPeer(DataGridColumn column, Boolean addParentInfo) ved System.Windows.Automation.Peers.DataGridAutomationPeer.GetCellItemPeer(DataGridCellInfo cellInfo) ved System.Windows.Automation.Peers.DataGridAutomationPeer.RaiseAutomationCellSelectedEvent(SelectedCellsChangedEventArgs e) ved System.Windows.Controls.DataGrid.OnSelectedCellsChanged(SelectedCellsChangedEventArgs e) ved System.Windows.Controls.DataGrid.NotifySelectedCellsChanged() ved System.Windows.Controls.DataGrid.ChangingSelectedCellsHelper.Dispose() ved System.Windows.Controls.DataGrid.AdjustPendingInfos() ved System.Windows.Controls.DataGrid.AdjustItemInfosAfterGeneratorChangeOverride() ved System.Windows.Controls.Primitives.Selector.AdjustNewContainers() ved System.Windows.Controls.Primitives.Selector.OnGeneratorStatusChanged(Object sender, EventArgs e) ved System.Windows.Controls.ItemContainerGenerator.SetStatus(GeneratorStatus value) ved System.Windows.Controls.ItemContainerGenerator.BatchGenerator.System.IDisposable.Dispose() ved System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure) ved System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) ved System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) ved System.Windows.FrameworkElement.MeasureCore(Size availableSize) ved System.Windows.UIElement.Measure(Size availableSize) ved System.Windows.ContextLayoutManager.UpdateLayout() ved System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) ved System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() ved System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) ved System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) ved System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) ved System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)The stacktrace might differ a bit from case-to-case but it always reaches OnSelectedCellsChanged(...) from which the road to the cell peer ctor is the same.
Reproduction Steps
None known. We have seen it across 12 different users over a period of 3 months.
Expected behavior
The client does not crash on a peer being created.
Actual behavior
The client crashes unexpectedly.
Regression?
Not that we know of.
Known Workarounds
We have just added a try-catch as an override on base.OnSelectedCellsChanged(...) but due to how rare the issue is, we have no way of knowing whether this solves the issues, or if it just leads to a bad state from which the client might/might not be able to continue.
Impact
Problem seems to be able to hit all users, regardless of them working on laptops, desktops, screen sizes, remote state and hardware acceleration.
Configuration
Other information
The datagrid we utilize is running with both sorting and filtering, so we have a lot of moving parts. In addition virtualization is also enabled, both horizontally and vertically since there might be a lot of columns, for a bunch of data.