dotnet/wpf · error · NotSupportedException

SR.RangeActionsNotSupported

Error message

SR.RangeActionsNotSupported

What it means

BindingListCollectionView.ValidateCollectionChangedEventArgs rejects any NotifyCollectionChangedAction.Add whose NewItems contains more than one element with NotSupportedException(SR.RangeActionsNotSupported). The view only supports single-item collection change notifications and does not implement range processing.

Solutions

  1. Add items one at a time so each notification carries exactly one NewItems element.
  2. Wrap multi-item inserts: suspend the view's refresh, raise Reset instead of a range Add, then Refresh the view.
  3. Change the source to raise NotifyCollectionChangedAction.Reset for bulk changes (clear + repopulate) rather than a multi-item Add.

Example fix

// before
void AddRange(IEnumerable<T> items) {
    foreach (var i in items) _inner.Add(i);
    OnCollectionChanged(new NotifyCollectionChangedEventArgs(Add, items.ToList())); // throws in view
}

// after
void AddRange(IEnumerable<T> items) {
    foreach (var i in items) _inner.Add(i); // per-item Add notifications, count == 1
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count > 1)
{
    // republish as Reset or per-item Adds instead of a range Add
}

Type guard

bool IsSingleItemAdd(NotifyCollectionChangedEventArgs e) =>
    e.Action != NotifyCollectionChangedAction.Add || (e.NewItems?.Count ?? 0) == 1;

Try / catch

try { view.Refresh(); } catch (NotSupportedException) { /* fall back to Reset+Refresh for bulk changes */ }

Prevention

When it happens

Trigger: The underlying IBindingList or collection raises a ListChanged/CollectionChanged Add event with a batch of items (multi-element NewItems), e.g. calling AddRange on an ObservableCollection-derived type that raises one multi-item Add notification.

Common situations: Bulk-loading data into a bound ObservableCollection via a custom AddRange that packs all items into one ChangeNotification; third-party collection libraries that emit multi-item Add events consumed by a BindingListCollectionView-backed view.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/dc6dd1f0b124f76a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:2433

                }
            }
        }

        private void OnLiveShapingDirty(object sender, EventArgs e)
        {
            IsLiveShapingDirty = true;
        }

        #endregion Live Shaping


        private void ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    if (e.NewItems.Count != 1)
                        throw new NotSupportedException(SR.RangeActionsNotSupported);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    if (e.OldItems.Count != 1)
                        throw new NotSupportedException(SR.RangeActionsNotSupported);
                    break;

                case NotifyCollectionChangedAction.Replace:
                    if (e.NewItems.Count != 1 || e.OldItems.Count != 1)
                        throw new NotSupportedException(SR.RangeActionsNotSupported);
                    break;

                case NotifyCollectionChangedAction.Move:
                    if (e.NewItems.Count != 1)
                        throw new NotSupportedException(SR.RangeActionsNotSupported);
                    if (e.NewStartingIndex < 0)
                        throw new InvalidOperationException(SR.CannotMoveToUnknownPosition);
                    break;

View on GitHub (pinned to 81131a70a4)