{"record":{"id":"4f461888e6b4de9d","repo":"dotnet/wpf","slug":"current-documentsequence-fixeddocument-or-fixedpage-not","errorCode":null,"errorMessage":"Current DocumentSequence, FixedDocument, or FixedPage not completed.","messagePattern":"Current DocumentSequence, FixedDocument, or FixedPage not completed\\.","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs","lineNumber":418,"sourceCode":"        /// </summary>\n        /// <returns>\n        /// Returns an interface to the newly created fixed page.\n        /// </returns>\n        /// <exception cref=\"ObjectDisposedException\">The FixedDocument has already been disposed</exception>\n        /// <exception cref=\"SR.ReachPackaging_PanelOrSequenceAlreadyOpen\">FixedPage is not completed.</exception>\n        public\n        IXpsFixedPageWriter\n        AddFixedPage(\n            )\n        {\n            ObjectDisposedException.ThrowIf(_metroPart is null || CurrentXpsManager.MetroPackage is null, typeof(XpsFixedDocumentReaderWriter));\n\n            //\n            // Only one page can be created/written at a time.\n            //\n            if (null != _currentPage)\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_PanelOrSequenceAlreadyOpen);\n            }\n\n\n            _linkTargetStream = new List<String>();\n\n            //\n            // Create the part and writer\n            //\n            PackagePart metroPart = this.CurrentXpsManager.GenerateUniquePart(XpsS0Markup.FixedPageContentType);\n            XpsFixedPageReaderWriter fixedPage = new XpsFixedPageReaderWriter(CurrentXpsManager, this, metroPart, _linkTargetStream, _pagesWritten + 1);\n\n            //\n            // Make the new page the current page\n            //\n            _currentPage = fixedPage;\n\n\n            //Here we used to add the fixed page to _pageCache, but _pageCache is never accessed if this object was created as an IXpsFixedDocumentWriter.","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs#L400-L436","documentation":"XpsFixedDocumentReaderWriter.AddFixedPage throws XpsPackagingException (ReachPackaging_PanelOrSequenceAlreadyOpen: 'Current DocumentSequence, FixedDocument, or FixedPage not completed.') when a page is already being written. The XPS writing model allows only one open page at a time; the previous page must be committed before a new one is added. The source guards on _currentPage != null.","triggerScenarios":"Calling AddFixedPage while the XpsFixedPageReaderWriter returned by a previous AddFixedPage call is still active (its Commit/Close not yet called).","commonSituations":"Looped page-generation code that forgets to commit each page; exception paths that skip page commit leaving _currentPage set; concurrent writes from multiple threads.","solutions":["Call Commit (and Close/dispose) on the current XpsFixedPageReaderWriter before calling AddFixedPage again.","Ensure exception handlers commit or abandon the in-flight page so _currentPage is cleared.","Wrap each page write in try/finally that disposes the page writer.","Serialize page writing on one thread; do not call AddFixedPage concurrently."],"exampleFix":"// before\nfor (var i = 0; i < pages; i++) { doc.AddFixedPage(); } // second call throws\n// after\nfor (var i = 0; i < pages; i++) {\n    var page = doc.AddFixedPage();\n    try { WritePageContent(page); page.Commit(); }\n    finally { page.Close(); }\n}","handlingStrategy":"try-catch","validationCode":"// only call when no page is open\nif (currentPageWriter != null && !currentPageWriterCommitted)\n    return; // or commit first","typeGuard":null,"tryCatchPattern":"try { var page = doc.AddFixedPage(); /* write, commit */ }\ncatch (XpsPackagingException ex) when (ex.Message.Contains(\"not completed\")) { /* commit outstanding page then retry */ }","preventionTips":["Always commit/close the previous page before AddFixedPage.","Use using/try-finally around page writers.","Never write pages from multiple threads."],"tags":["wpf","xps","invalid-state","sequential-writes"],"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-22T01:17:13.364Z"}