Cysharp / ObservableCollections

High performance observable collections and synchronized views, for WPF, Blazor, Unity.
MIT License
606 stars 46 forks source link

WPF, AddRange() throw Exception #67

Closed zerodev1200 closed 2 months ago

zerodev1200 commented 2 months ago

Congratulations on the release of v3.0.0...!

I apologize for bringing this up right after the release, but when using AddRange on an ObservableList that called .CreateView(x => x) and .ToNotifyCollectionChanged() in WPF, an exception occurs at the following location:

AlternateIndexList.InsertIterator.Dispose() => iter.Reset(); NotSupportedException 'Specified method is not supported.'

If I comment out that part and perform AddRange, it results in the following exception, similar to the previous issue: System.NotSupportedException: 'Range actions are not supported.'

FutureTD commented 2 months ago

Having the same issue myself.

neuecc commented 2 months ago

I have released v3.0.1, which should fix the issues.

It's a bug for Dispose to call Reset! Thank you, I have fixed it.

There's no need to support Range as it's a framework issue (users on unsupported platforms should avoid using Range). However, I thought about it and realized that INotifyCollectionChange is only used in XAML frameworks, and if most of those frameworks don't support it, it becomes meaningless. So, I've added a feature to break down batch notifications to multiple single notifications when they arrive.

Additionally, I've added ToNotifyCollectionChangedSlim to ObservableList. This is designed to be the fastest and lightest conversion method, but it doesn't break down Range operations (it will throw runtime exceptions on unsupported platforms).

zerodev1200 commented 2 months ago

Thank you! I am always amazed at your ideas and depth of insight!