We often get this exception for the DataGrid and we are trying to reproduce it, but we are unable to find the cause of this issue.
The StackTrace is either this:
System.Windows.Controls.ItemCollection.GetItemAt(Int32 index) en System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell cell) en System.Windows.Controls.DataGridCell.PrepareCell(Object item, DataGridRow ownerRow, Int32 index) en System.Windows.Controls.DataGridCell.PrepareCell(Object item, ItemsControl cellsPresenter, DataGridRow ownerRow) en System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) en System.Windows.Controls.ItemContainerGenerator.OnItemReplaced(Object oldItem, Object newItem, Int32 index) en System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) en System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) en System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) en System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) en System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) en System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) en System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) en System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) en System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) en System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) en System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex) en System.Windows.Controls.MultipleCopiesCollection.set_CopiedItem(Object value) en System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget target) en System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget target) en System.Windows.Controls.DataGridRow.OnNotifyRowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) en System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.Controls.DataGridRow.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) en System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) en System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) en System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) en System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid) en System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item) en System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) en System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) en System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized) en System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex, Size layoutSlotSize) en System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(Size layoutSlotSize) en System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) en System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) en System.Windows.FrameworkElement.MeasureCore(Size availableSize) en System.Windows.UIElement.Measure(Size availableSize) en System.Windows.ContextLayoutManager.UpdateLayout() en System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) en System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() en System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) en System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) en System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) en MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Or this one:
at System.Windows.Controls.ItemCollection.GetItemAt(Int32 index) at System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell cell) at System.Windows.Controls.DataGridCell.PrepareCell(Object item, DataGridRow ownerRow, Int32 index) at System.Windows.Controls.DataGridCell.PrepareCell(Object item, ItemsControl cellsPresenter, DataGridRow ownerRow) at System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(Boolean forcePrepareCells) at System.Windows.Controls.DataGridRow.SyncProperties(Boolean forcePrepareCells) at System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid) 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.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) at System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized) at System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex, Size layoutSlotSize) at System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(Size layoutSlotSize) 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.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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
We found some posts about EnableColumnVirtualization (set to false), but this doesn't help, we still get the same exception. We are pretty much out of ideas on how we can reproduce or fix this exception. Does anyone have an idea on how to solve this issue?