dotnet/wpf · error · NotSupportedException

SR.RangeActionsNotSupported

Error message

SR.RangeActionsNotSupported

What it means

CollectionView only supports single-item change notifications. ValidateCollectionChangedEventArgs throws NotSupportedException for Add events whose NewItems contains more than one item (range Add). Underlying collections must raise separate single-item notifications for the view to process them.

Solutions

  1. Raise one single-item Add event per element in AddRange (optionally wrapped in DeferRefresh on the view)
  2. Change the notification action to Reset for bulk changes
  3. Use a collection library whose bulk operations are WPF-compatible (e.g. raising Reset or per-item events)

Example fix

// before
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItems)); // range
// after
foreach (var item in newItems)
    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
Defensive patterns

Strategy: validation

Validate before calling

if (e.Action == NotifyCollectionChangedAction.Add && (e.NewItems == null || e.NewItems.Count > 1))
    throw new ArgumentException("CollectionView requires single-item Add notifications.");

Type guard

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

Try / catch

try { OnCollectionChanged(e); }
catch (NotSupportedException) { foreach (var i in e.NewItems) RaiseSingleAdd(i); }

Prevention

When it happens

Trigger: Raising CollectionChanged with NotifyCollectionChangedAction.Add and a NewItems list of count > 1 (or null) from a custom INotifyCollectionChanged collection consumed by a CollectionView.

Common situations: Custom observable collections implementing bulk AddRange with a single multi-item Add event; third-party collections that batch notifications; ports of collections that assumed range actions were allowed.

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/7e65b8b12c516c99. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs:1952

            // if changes remain (because we ran out of time), reschedule them
            if (unprocessedChanges != null && unprocessedChanges.Count > 0)
            {
                DeferProcessing(unprocessedChanges);
            }

            _tempChangeLog = s_emptyList;

            return null;
        }

        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);
                    if (e.OldStartingIndex < 0)
                        throw new InvalidOperationException(SR.RemovedItemNotFound);
                    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)

View on GitHub (pinned to 81131a70a4)