-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
- .NET Core Version: 3.1.400-preview-015151
- Windows version: win10 2004
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
ListCollectionView.Refresh runs after CollectionView.DetachFromSourceCollection (or something else) set SourceCollection to null and throws an exception
Actual behavior:
For some reason (unfortunately, im unable to manufacture a simple repro, it only happens seemingly random at runtime on one specific view when it is discarded/goes out of scope), ListCollectionView.Refresh runs after a CollectionView.DetachFromSourceCollection and throws an argument null exception. Trace:
System.ArgumentNullException: Collection cannot be null.
Parameter name: c
at System.Collections.ArrayList..ctor(ICollection c)
at System.Windows.Data.ListCollectionView.b__1_0()
at MS.Internal.Data.SynchronizationInfo.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.BindingOperations.AccessCollection(IEnumerable collection, Action accessMethod, Boolean writeAccess)
at System.Windows.Data.ListCollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.ProcessChangeLog(ArrayList changeLog, Boolean processAll)
at System.Windows.Data.CollectionView.ProcessInvoke(Object arg)
at MS.Internal.Data.DataBindEngine.ProcessCrossThreadRequests()
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)
While im not 100% sure its CollectionView.DetachFromSourceCollection which sets the SourceCollection to null, it seems highly likely.
Expected behavior:
Do nothing if the source collection is gone (or clear the contents of the shadow collection? Is there a scenario where this happens legit, i.e. the view is still shown to the user? It does not seem so)
Minimal repro:
Unfortunately, the app is rather complex and i cannot pinpoint the exact point of failure. It happens on a view which has a CollectionViewSource with grouping in its resources which is used by a listview. But we have similar things in other places and it works.
Workaround:
We are able to work around it be creating the collectionviewsource in the viewmodel, and bind the listview itemssource to its CollectionView