{"record":{"id":"754f650281b7e04e","repo":"dotnet/wpf","slug":"sr-reachserialization-fixeddocumentindocument","errorCode":null,"errorMessage":"SR.ReachSerialization_FixedDocumentInDocument","messagePattern":"SR\\.ReachSerialization_FixedDocumentInDocument","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs","lineNumber":700,"sourceCode":"        RegisterDocumentSequenceEnd()\n        {\n            //\n            // It is invalid to have a document sequence with no fixed documents\n            // 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        }","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs#L682-L718","documentation":"RegisterDocumentStart rejects starting a FixedDocument while another document is still open (_documentStartState true). XPS forbids nested FixedDocuments, so a second RegisterDocumentStart without RegisterDocumentEnd throws XpsSerializationException(SR.ReachSerialization_FixedDocumentInDocument).","triggerScenarios":"Calling RegisterDocumentStart twice without an intervening RegisterDocumentEnd, i.e. nesting a FixedDocument inside an open FixedDocument.","commonSituations":"Custom writers that miss the end-of-document call between documents; re-entrant or event-driven serialization; recovery paths that left _documentStartState set after an exception.","solutions":["Call RegisterDocumentEnd before starting the next document.","Pair every RegisterDocumentStart with exactly one RegisterDocumentEnd in the writer loop.","Reinitialize the serialization manager if a previous error left the document state machine inconsistent."],"exampleFix":"// before\nmanager.RegisterDocumentStart();\nmanager.RegisterDocumentStart(); // throws\n// after\nmanager.RegisterDocumentStart();\n// ...serialize document...\nmanager.RegisterDocumentEnd();\nmanager.RegisterDocumentStart();","handlingStrategy":"validation","validationCode":"bool docOpen = _docStarted && !_docEnded;\nif (docOpen) throw new InvalidOperationException(\"Previous FixedDocument was not ended.\");","typeGuard":null,"tryCatchPattern":"try { manager.RegisterDocumentStart(); }\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"FixedDocumentInDocument\")) { manager.RegisterDocumentEnd(); manager.RegisterDocumentStart(); }","preventionTips":["Pair RegisterDocumentStart with exactly one RegisterDocumentEnd","Follow the canonical Register* call order","Recreate the manager after aborted serializations"],"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"}