Unplanned
Last Updated: 18 Oct 2024 15:10 by Martin Ivanov
Martin Ivanov
Created on: 18 Oct 2024 15:10
Category: TreeListView
Type: Bug Report
0
TreeListView: NullReferenceException and InvalidOperationException thrown when the ItemsSource collection is marked with EnableCollectionSynchronization and then updated on another thread

One of the following two exceptions occur when the BindingOperations.EnableCollectionSynchronization() is used with the ItemsSource of RadTreeListView:

  • System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'
  • System.NullReferenceException: 'Object reference not set to an instance of an object.'

When using the EnableCollectionSynchronization, the corresponding items control should allow updates of the ItemsSource collection on different threads. This is valid if the requirements to use the EnableCollectionSynchronization method are met.

The exception stack traces are:

InvalidOperationException
   at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion() in /_/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs:line 432
   at System.Collections.Generic.List`1.Enumerator.MoveNext() in /_/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs:line 1130
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at Telerik.Windows.Data.EnumerableExtensions.<SelectRecursive>d__15`1.MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at Telerik.Windows.Data.HierarchicalCollectionViewBase.PopulateInternalList(IQueryable view)
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
   at Telerik.Windows.Data.HierarchicalCollectionViewBase.get_InternalCount()
   at Telerik.Windows.Data.DataItemCollection.get_Item(Int32 index)
   at Telerik.Windows.Controls.GridView.Rows.GetRowItemsAtRange(Int32 startIndex, Int32 endIndex)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RealizeRows(Int32 startIndex, Int32 endIndex, Double& verticalOffset, HashSet`1& realizedRows)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.MeasureOverride(Size availableSize)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)
--------------------------------------

NullReferenceException
   at Telerik.Windows.Data.QueryableCollectionView.InternalGetItemAt(Int32 index) in Telerik.Windows.Data\QueryableCollectionView.cs:line 3081
   at Telerik.Windows.Controls.GridView.Rows.GetRowItemsAtRange(Int32 startIndex, Int32 endIndex)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RealizeRows(Int32 startIndex, Int32 endIndex, Double& verticalOffset, HashSet`1& realizedRows)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.MeasureOverride(Size availableSize)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)

To work this around dispatch the updates of the ItemsSource collection to the main UI thread.

 Dispatcher.BeginInvoke(new Action(() =>
 {
    // add/remove items from the source collection
 }));

0 comments