{"record":{"id":"7579090dfdac22c4","repo":"dotnet/wpf","slug":"sr-reachserialization-fixedpageinpage-757909","errorCode":null,"errorMessage":"SR.ReachSerialization_FixedPageInPage","messagePattern":"SR\\.ReachSerialization_FixedPageInPage","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs","lineNumber":884,"sourceCode":"            // It is invalid to have a document with no fixed pages\n            // If no fixed pages have been searialzed throw\n            //\n            if( _pageNumber <= 0 )\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_NoFixedPages);\n            }\n            //\n            // Exiting Document  Started state\n            //\n            _documentStartState = false;\n        }\n\n        void\n        IXpsSerializationManager.RegisterPageStart()\n        {\n            if( _pageStartState )\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_FixedPageInPage);\n            }\n            //\n            // Entering Page  Started state\n            //\n            _pageStartState = true;\n            //\n            // Increment the number of documents serialized\n            //\n            _pageNumber += 1;\n        }\n\n\n        void\n        IXpsSerializationManager.RegisterPageEnd()\n        {\n            //\n            // Exiting Page  Started state\n            //","sourceCodeStart":866,"sourceCodeEnd":902,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs#L866-L902","documentation":"IXpsSerializationManager.RegisterPageStart enforces that pages cannot nest: if a FixedPage is already open (_pageStartState), starting another page throws XpsSerializationException(SR.ReachSerialization_FixedPageInPage). XPS requires each FixedPage to be ended before the next begins.","triggerScenarios":"Calling RegisterPageStart twice without RegisterPageEnd — duplicate page-start callbacks, a paginator that re-enters page production, or a retry path that restarts the current page without ending it first.","commonSituations":"Custom XPS writers handling WriteAsync callbacks that fire twice; retry logic around failing pages missing cleanup; re-entrancy from print-events triggering a second page start.","solutions":["Always pair RegisterPageStart with RegisterPageEnd before starting the next page (try/finally around page serialization).","On page-level failure, call RegisterPageEnd (or abort the whole document) before retrying, never call RegisterPageStart again directly.","Guard the page-start call with a local 'pageOpen' flag in your serializer to detect double-entry.","Use XpsDocumentWriter with a DocumentPaginator to avoid manual page lifecycle management."],"exampleFix":"// before\nmanager.RegisterPageStart();\nmanager.RegisterPageStart(); // nested page\n// after\nmanager.RegisterPageStart();\n// ... serialize page ...\nmanager.RegisterPageEnd();\nmanager.RegisterPageStart(); // next page","handlingStrategy":"try-catch","validationCode":"if (pageOpen)\n    throw new InvalidOperationException(\"RegisterPageStart called while another FixedPage is open; call RegisterPageEnd first.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    manager.RegisterPageStart();\n}\ncatch (System.Windows.Xps.XpsSerializationException ex) when (ex.Message.Contains(\"page\"))\n{\n    // a page is already open: end it before starting the new one\n    manager.RegisterPageEnd();\n    manager.RegisterPageStart();\n}","preventionTips":["Guard page-start with a pageOpen flag to catch double entry (e.g. duplicate async callbacks).","Use try/finally around each page so RegisterPageEnd always executes.","Deduplicate async write callbacks before they trigger a second page start."],"tags":["wpf","xps","state-machine","serialization"],"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"}