{"record":{"id":"083d6c6790a33f03","repo":"dotnet/wpf","slug":"sr-prevoiuspartialpagecontentoutstanding","errorCode":null,"errorMessage":"SR.PrevoiusPartialPageContentOutstanding","messagePattern":"SR\\.PrevoiusPartialPageContentOutstanding","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs","lineNumber":154,"sourceCode":"                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PageContent)), nameof(value));\n            }\n\n            if (fp.IsInitialized)\n            {\n                _pages.Add(fp);\n            }\n            else\n            {\n                DocumentsTrace.FixedFormat.FixedDocument.Trace($\"Page {_pages.Count} Deferred\");\n                if (_partialPage == null)\n                {\n                    _partialPage = fp;\n                    _partialPage.ChangeLogicalParent(this);\n                    _partialPage.Initialized += new EventHandler(OnPageLoaded);\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.PrevoiusPartialPageContentOutstanding);\n                }\n            }\n        }\n\n        ///<summary>\n        /// Called when text appears under the tag in markup\n        ///</summary>\n        ///<param name=\"text\">\n        /// Text to Add to the Object\n        ///</param>\n        /// <ExternalAPI/>\n        void IAddChild.AddText(string text)\n        {\n            XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);\n        }\n        #endregion\n\n        #region IUriContext","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs#L136-L172","documentation":"This InvalidOperationException is thrown when AddChild on FixedDocument is given a new partial PageContent while a previously added partial page has not yet finished initializing. FixedDocument supports only one outstanding partially-loaded page at a time because it must attach an Initialized handler and logical parent to exactly one pending page.","triggerScenarios":"Adding multiple asynchronous/partial PageContent entries in quick succession (e.g. from async XPS loading) before the prior partial page's Initialized event fires.","commonSituations":"Async XPS document parsing or streaming scenarios; adding several page contents before UI/binder events complete; double-adding the same page content.","solutions":["Wait for the previous partial page's Initialized event before adding the next PageContent","Add fully initialized PageContent objects instead of partial ones","Ensure no duplicate AddChild calls for the same pending page","Catch InvalidOperationException and defer the add via a queue drained on page load"],"exampleFix":"// before\nforeach (var pc in pageContents) fixedDocument.AddChild(pc); // throws if a partial page is pending\n// after\nvoid AddNext(IEnumerator<PageContent> e) {\n    if (!e.MoveNext()) return;\n    ((IAddChild)fixedDocument).AddChild(e.Current);\n    Dispatcher.CurrentDispatcher.BeginInvoke(() => AddNext(e), System.Windows.Threading.DispatcherPriority.Loaded);\n}","handlingStrategy":"try-catch","validationCode":"bool canAdd = fixedDocument._pages.All(p => p.IsInitialized); // check via public surface: only add PageContent once previous ones report Initialized","typeGuard":null,"tryCatchPattern":"try { ((IAddChild)fixedDocument).AddChild(pageContent); } catch (InvalidOperationException) { pendingPages.Enqueue(pageContent); }","preventionTips":["Wait for the previous partial page's Initialized event before adding the next","Avoid adding multiple asynchronous PageContent objects in a tight loop","Queue page additions and drain them on page-load events"],"tags":["wpf","invalidoperationexception","xps-fixeddocument","async-loading","state-conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}