{"record":{"id":"b2d9f0a8c8e4d657","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedcollectionchangeaction-args-action-b2d9f0","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedCollectionChangeAction, args.Action)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedCollectionChangeAction, args\\.Action\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs","lineNumber":747,"sourceCode":"                    if (paginator == null)\n                    {\n                        throw new ApplicationException(SR.DocumentReferenceHasInvalidDocument);\n                    }\n\n                    int addedPages = paginator.PageCount;\n                    int firstPage = pageCount - addedPages;\n\n                    if (addedPages > 0)\n                    {\n                        DocumentsTrace.FixedDocumentSequence.Content.Trace($\"_OnCollectionChange: Add with IDP {paginator.GetHashCode()}\");\n                        _paginator.NotifyPaginationProgress(new PaginationProgressEventArgs(firstPage, addedPages));\n                        _paginator.NotifyPagesChanged(new PagesChangedEventArgs(firstPage, addedPages));\n                    }\n                }\n            }\n            else\n            {\n                throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, args.Action));\n            }\n        }\n\n\n        // Take a child paginator and a page nubmer, find which global page number it corresponds to\n        private bool _SynthesizeGlobalPageNumber(DynamicDocumentPaginator childPaginator, int childPageNumber, out int pageNumber)\n        {\n            pageNumber = 0;\n            foreach (DocumentReference docRef in References)\n            {\n                DynamicDocumentPaginator innerPaginator = GetPaginator(docRef);\n                if (innerPaginator != null)\n                {\n                    if (innerPaginator == childPaginator)\n                    {\n                        pageNumber += childPageNumber;\n                        return true;\n                    }","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs#L729-L765","documentation":"DocumentSequence._OnCollectionChanged reacts to changes in the sequence's child document collection. When the collection change action is something other than Add, Remove, or Replace, the handler has no logic to update paginators/child blocks and throws NotSupportedException with UnexpectedCollectionChangeAction. It guards an internal expectation that only supported INotifyCollectionChanged actions reach the sequence.","triggerScenarios":"Calling an API that raises CollectionChanged on DocumentSequence.References (or the underlying collection) with NotifyCollectionChangedAction.Reset or Move; any code mutating the References collection with a range action or custom action value.","commonSituations":"Custom collection implementations raising Reset after bulk edits; third-party code replacing the References collection behavior; WPF internal Reset notifications triggered when a FixedDocumentSequence reloads content.","solutions":["Only modify DocumentSequence.References through supported Add/Remove/Replace operations","Avoid bulk mutations that fire NotifyCollectionChangedAction.Reset; rebuild the collection instead of resetting it","Wrap References manipulation in try/catch NotSupportedException and fall back to recreating the DocumentSequence","If you own the collection class, ensure it never raises Move/Reset; raise discrete Add/Remove events instead"],"exampleFix":"// before\nreferences.Clear(); // fires Reset -> NotSupportedException\n// after\nforeach (var item in references.ToList()) { references.Remove(item); }","handlingStrategy":"try-catch","validationCode":"if (args.Action != NotifyCollectionChangedAction.Add && args.Action != NotifyCollectionChangedAction.Remove && args.Action != NotifyCollectionChangedAction.Replace)\n    throw new NotSupportedException($\"Action {args.Action} is not supported by DocumentSequence.References\");","typeGuard":"bool IsSupportedAction(NotifyCollectionChangedAction a) => a is NotifyCollectionChangedAction.Add or NotifyCollectionChangedAction.Remove or NotifyCollectionChangedAction.Replace;","tryCatchPattern":"try { references.Add(docRef); }\ncatch (NotSupportedException ex) { /* recreate DocumentSequence or log */ }","preventionTips":["Mutate References only with Add/Remove/Replace","Avoid Clear()/Move/Reset on References","Wrap bulk updates in rebuild-the-sequence logic"],"tags":["wpf","documents","collections","not-supported"],"backgroundTag":"unsupported-collection-change-action","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"}