System.Reflection.TargetInvocationException: "An error occurred while dispatching a call to the UI Thread"
Inner Exception
ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"
at Stylet.Execute.OnUIThreadSync(Action action)
at Stylet.BindableCollection`1.RemoveItem(Int32 index)
at System.Collections.ObjectModel.Collection`1.Remove(T item)
Discussed in #306
Originally posted by Yoooi0 November 21, 2021
There seems to be an issue with thread safety in BindableCollection.
When two threads modify the collection at the same time, one calling ClearItems, the other calling RemoveItem, it can cause
OnCollectionChangingto throw an exception.Example timeline:
collection.ClearItems()Execute.OnUIThreadSynccollection.Remove(firstItem), this callsRemoveItemwithindexargument set to0base.ClearItems()Execute.OnUIThreadSyncOnCollectionChangingbecause the item at index 0 does not exist anymore