{"record":{"id":"85410dbeebd4e0d9","repo":"dotnet/wpf","slug":"sr-reachserialization-fixeddocumentinpage","errorCode":null,"errorMessage":"SR.ReachSerialization_FixedDocumentInPage","messagePattern":"SR\\.ReachSerialization_FixedDocumentInPage","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs","lineNumber":704,"sourceCode":"            // If no fixed documents have been searialzed throw\n            //\n            if (_documentNumber <= 0)\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_NoFixedDocuments);\n            }\n        }\n\n        internal\n        void\n        RegisterDocumentStart()\n        {\n            if( _documentStartState )\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_FixedDocumentInDocument);\n            }\n            if( _pageStartState)\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_FixedDocumentInPage);\n            }\n            //\n            // Entering Document  Started state\n            //\n            _documentStartState = true;\n            //\n            // Increment the number of documents serialized\n            //\n            _documentNumber += 1;\n            //\n            // Clearing the number of pages for this document\n            //\n            _pageNumber = 0;\n        }\n\n        internal\n        void\n        RegisterDocumentEnd()","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs#L686-L722","documentation":"RegisterDocumentStart also rejects starting a FixedDocument while a FixedPage is still open (_pageStartState true). A document may not begin inside a page, so XpsSerializationException(SR.ReachSerialization_FixedDocumentInPage) is thrown.","triggerScenarios":"Calling RegisterDocumentStart after RegisterPageStart but before RegisterPageEnd — starting a document nested inside an open page.","commonSituations":"Incorrect ordering of Register* calls in custom XPS writers (page opened, then document started); recursion into document serialization from within page content generation.","solutions":["Call RegisterPageEnd before RegisterDocumentStart.","Enforce the canonical call order: DocumentSequenceStart → DocumentStart → PageStart → PageEnd → DocumentEnd → SequenceEnd.","Check _pageStartState-equivalent logic in your wrapper so documents never start inside pages."],"exampleFix":"// before\nmanager.RegisterPageStart();\nmanager.RegisterDocumentStart(); // throws\n// after\nmanager.RegisterPageStart();\nmanager.RegisterPageEnd();\nmanager.RegisterDocumentStart();","handlingStrategy":"validation","validationCode":"bool pageOpen = _pageStarted && !_pageEnded;\nif (pageOpen) throw new InvalidOperationException(\"Cannot start a document inside an open page.\");","typeGuard":null,"tryCatchPattern":"try { manager.RegisterDocumentStart(); }\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"FixedDocumentInPage\")) { manager.RegisterPageEnd(); manager.RegisterDocumentStart(); }","preventionTips":["Never start documents from within page-content generation code","Enforce DocumentStart → PageStart → PageEnd ordering in wrappers","Avoid recursive serialization calls inside page rendering"],"tags":["wpf","xps","serialization","document-structure","state-machine"],"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"}