Can you help us solve crashes in DataGrid WPF?

Geerts, Eric 0 Reputation points
2024-02-14T09:19:06.07+00:00

We are experiencing crashes in particular environments on customer sites in our WPF application. The callstack points to the DataGrid control, which contains in these cases CheckBoxes which are ToggleButtons (callstack). Our codebase extends the DataGrid control but has been untouched since 2016 For some users of a particular customer this reproduces instantly and for others sometimes. Internally we don't have a repro nor do other customers crash. We don't formally support Automation in our WPF application but these customers may use Automation on their system nonetheless.

I've searched around and I found very similair callstacks originating from other controls than ToggleButton. From what I understand have these been fixed in .NET updates: https://developercommunity.visualstudio.com/t/vs-1602-crashes-opening-naming-style-window/546969 https://github.com/dotnet/wpf/issues/4279#issuecomment-1068216694 I've also tried the workaround mentioned in the latter link, but to no avail.

Callstack (Originally in Dutch)

System.ArgumentNullException: Value cannot be null. Parameter name: item
    at System.Windows.Automation.Peers.DataGridItemAutomationPeer..ctor(Object item, DataGridAutomationPeer dataGridPeer)
    at System.Windows.Automation.Peers.DataGridAutomationPeer.CreateItemAutomationPeer(Object item)
    at System.Windows.Automation.Peers.ItemsControlAutomationPeer.GetChildrenCore()
    at System.Windows.Automation.Peers.DataGridAutomationPeer.GetChildrenCore()
    at System.Windows.Automation.Peers.AutomationPeer.EnsureChildren()
    at System.Windows.Automation.Peers.AutomationPeer.GetChildren()
    at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
    at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
    at System.Windows.Automation.Peers.AutomationPeer.isDescendantOf(AutomationPeer parent)
    at System.Windows.Automation.Peers.AutomationPeer.ValidateConnected(AutomationPeer connectedPeer)
    at MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
    at System.Windows.Automation.Peers.AutomationPeer.ProviderFromPeer(AutomationPeer peer)
    at System.Windows.Automation.Peers.AutomationPeer.RaisePropertyChangedEvent(AutomationProperty property, Object oldValue, Object newValue)
    at System.Windows.Automation.Peers.ToggleButtonAutomationPeer.RaiseToggleStatePropertyChangedEvent(Nullable`1 oldValue, Nullable`1 newValue)
    at System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
    at System.Windows.DependencyObject.ClearValueCommon(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata)
    at System.Windows.DependencyObject.ClearValue(DependencyProperty dp)
    at System.Windows.Data.BindingOperations.ClearBinding(DependencyObject target, DependencyProperty dp)
    at MyNameSpace.MyDataGridCellValue.BindCellValue(DataGridCell cell, FrameworkElement el)
 in MyDataGridCellValue.cs:line 186
    at MyDataGridCellValue.BindCellProperties(DataGridCell cell, FrameworkElement el)
 in MyDataGridCellValue.cs:line 173
    at MyNamespace.MyDataGrid.OnLoadingRow(DataGridRow dgRow)
 in MyDataGrid.cs:line 1515
    at MyNamespace.MyDataGrid.OnLoadingRow(DataGridRowEventArgs e)
 in MyDataGrid.cs:line 1279
    at System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item)
    at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
    at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
    at System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
    at System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized, Boolean isBeforeViewport)
    at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(IItemContainerGenerator& generator, IContainItemStorage& itemStorageProvider, IContainItemStorage& parentItemStorageProvider, Object& parentItem, Boolean& hasUniformOrAverageContainerSizeBeenSet, Double& computedUniformOrAverageContainerSize, Double& computedUniformOrAverageContainerPixelSize, Boolean& computedAreContainersUniformlySized, Boolean& hasAnyContainerSpanChanged, IList& items, Object& item, IList& children, Int32& childIndex, Boolean& visualOrderChanged, Boolean& isHorizontal, Size& childConstraint, Rect& viewport, VirtualizationCacheLength& cacheSize, VirtualizationCacheLengthUnit& cacheUnit, Boolean& foundFirstItemInViewport, Double& firstItemInViewportOffset, Size& stackPixelSize, Size& stackPixelSizeInViewport, Size& stackPixelSizeInCacheBeforeViewport, Size& stackPixelSizeInCacheAfterViewport, Size& stackLogicalSize, Size& stackLogicalSizeInViewport, Size& stackLogicalSizeInCacheBeforeViewport, Size& stackLogicalSizeInCacheAfterViewport, Boolean& mustDisableVirtualization, Boolean isBeforeFirstItem, Boolean isAfterFirstItem, Boolean isAfterLastItem, Boolean skipActualMeasure, Boolean skipGeneration, Boolean& hasBringIntoViewContainerBeenMeasured, Boolean& hasVirtualizingChildren)
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure)
    at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
    at System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.ContextLayoutManager.UpdateLayout()
    at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
    at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
    at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
    at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,536 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,698 questions
{count} votes