{"record":{"id":"e3508c572cd43ff2","repo":"dotnet/wpf","slug":"sr-rangeactionsnotsupported-documentsequence","errorCode":null,"errorMessage":"SR.RangeActionsNotSupported","messagePattern":"SR\\.RangeActionsNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs","lineNumber":717,"sourceCode":"            DocumentReference docRef = (DocumentReference)sender;\n\n            if (docRef == _partialRef)\n            {\n                DocumentsTrace.FixedDocumentSequence.Content.Trace($\"Loaded DocumentReference {_references.Count}\");\n                _partialRef.Initialized -= new EventHandler(_OnDocumentReferenceInitialized);\n                _partialRef = null;\n                _references.Add(docRef);\n            }\n        }\n\n\n        private void _OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)\n        {\n            if (args.Action == NotifyCollectionChangedAction.Add)\n            {\n                if (args.NewItems.Count != 1)\n                {\n                    throw new NotSupportedException(SR.RangeActionsNotSupported);\n                }\n                else\n                {\n                    // get the affected item\n                    object item = args.NewItems[0];\n\n                    DocumentsTrace.FixedDocumentSequence.Content.Trace($\"_OnCollectionChange: Add {item.GetHashCode()}\");\n                    AddLogicalChild(item);\n\n                    int pageCount = this.PageCount;\n                    DynamicDocumentPaginator paginator = GetPaginator((DocumentReference)item);\n                    if (paginator == null)\n                    {\n                        throw new ApplicationException(SR.DocumentReferenceHasInvalidDocument);\n                    }\n\n                    int addedPages = paginator.PageCount;\n                    int firstPage = pageCount - addedPages;","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs#L699-L735","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add DocumentReference items one at a time so each Add notification contains a single item","Replace AddRange/bulk insert with a loop of single Add calls","Use Reset action (repopulate) or re-create the collection for bulk changes","Patch custom collection wrappers to emit per-item notifications"],"exampleFix":"// before\nrefs.AddRange(newRefs); // raises multi-item Add\n// after\nforeach (var r in newRefs) refs.Add(r); // one item per notification","handlingStrategy":"validation","validationCode":"if (args.Action == NotifyCollectionChangedAction.Add && args.NewItems.Count > 1) throw new NotSupportedException(\"Add one item at a time\");","typeGuard":null,"tryCatchPattern":"try { refs.Add(docRef); } catch (NotSupportedException ex) { log.Error(\"Range Add not supported\", ex); }","preventionTips":["Avoid AddRange on collections observed by DocumentSequence","Use single-item Add notifications in custom collections","Use Reset for bulk structural changes"],"tags":["wpf","collections","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}