-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
When updating the SDK from Preview 5 to the latest Preview 6 nightly (3.0.100-preview6-012131) and recompiling my app, I started getting runtime exceptions in ListCollectionView due to changes in AddRange.
I have an extension method keyed on ICollection<T> called AddRange that accepts an IEnumerable<T>. It loops over the items and calls Add(T item) on the collection. I believe this is a common extension method people have added for convenience.
The trouble is that the new implementation of AddRange on Collection<T> does the add as a bulk insert at the end. This changes the behavior for consumers like the WPF ListCollectionView. That type listens for property changes on ObservableCollection<T>, but it does not support bulk operations, and throws.
https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L2521
The net effect here is that a common helper method that is used in many WPF apps (AddRange to an ObservableCollection<T> no longer binds and the replacement method's behavior has a negative and observable side effect.
The workaround is to create an AddRangeScalar method with the same signature as the original AddRange extension method and ensure that's always called. However, that has a wide impact on existing code and it's really easy for people to miss it and trigger a runtime exception on that code path.