dotnet/wpf · error · NotSupportedException

SR.RangeActionsNotSupported

Error message

SR.RangeActionsNotSupported

What it means

DocumentSequence listens to collection-change events on its DocumentReferences and only supports NotifyCollectionChangedAction.Add for a single new item. Any Add action whose NewItems contains more than one item throws NotSupportedException with SR.RangeActionsNotSupported.

Solutions

  1. Add DocumentReference items one at a time so each Add notification contains a single item
  2. Replace AddRange/bulk insert with a loop of single Add calls
  3. Use Reset action (repopulate) or re-create the collection for bulk changes
  4. Patch custom collection wrappers to emit per-item notifications

Example fix

// before
refs.AddRange(newRefs); // raises multi-item Add
// after
foreach (var r in newRefs) refs.Add(r); // one item per notification
Defensive patterns

Strategy: validation

Validate before calling

if (args.Action == NotifyCollectionChangedAction.Add && args.NewItems.Count > 1) throw new NotSupportedException("Add one item at a time");

Try / catch

try { refs.Add(docRef); } catch (NotSupportedException ex) { log.Error("Range Add not supported", ex); }

Prevention

When it happens

Trigger: Raising/marshalling a collection-changed Add affecting multiple items (range add) against the collection the DocumentSequence observes — e.g. AddRange-style bulk additions or a custom collection firing a multi-item Reset/Add.

Common situations: Custom observable collections that raise Add with several items instead of one per item; bulk-loading references into the underlying collection; third-party collection libraries that batch notifications.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs:717

            DocumentReference docRef = (DocumentReference)sender;

            if (docRef == _partialRef)
            {
                DocumentsTrace.FixedDocumentSequence.Content.Trace($"Loaded DocumentReference {_references.Count}");
                _partialRef.Initialized -= new EventHandler(_OnDocumentReferenceInitialized);
                _partialRef = null;
                _references.Add(docRef);
            }
        }


        private void _OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Add)
            {
                if (args.NewItems.Count != 1)
                {
                    throw new NotSupportedException(SR.RangeActionsNotSupported);
                }
                else
                {
                    // get the affected item
                    object item = args.NewItems[0];

                    DocumentsTrace.FixedDocumentSequence.Content.Trace($"_OnCollectionChange: Add {item.GetHashCode()}");
                    AddLogicalChild(item);

                    int pageCount = this.PageCount;
                    DynamicDocumentPaginator paginator = GetPaginator((DocumentReference)item);
                    if (paginator == null)
                    {
                        throw new ApplicationException(SR.DocumentReferenceHasInvalidDocument);
                    }

                    int addedPages = paginator.PageCount;
                    int firstPage = pageCount - addedPages;

View on GitHub (pinned to 81131a70a4)