{"record":{"id":"522b9650dba9cc8e","repo":"dotnet/wpf","slug":"sr-reachserialization-fixedpageinpage","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/XpsOMSerializationManager.cs","lineNumber":651,"sourceCode":"        OnXPSSerializationProgressChanged(\n            object operationState\n            )\n        {\n            XpsSerializationProgressChangedEventArgs e = operationState as XpsSerializationProgressChangedEventArgs;\n\n            if (XpsSerializationProgressChanged != null)\n            {\n                XpsSerializationProgressChanged(this, e);\n            }\n        }\n\n        internal\n        void \n        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        internal\n        void\n        RegisterPageEnd()\n        {\n            //\n            // Exiting Page  Started state\n            //","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs#L633-L669","documentation":"RegisterPageStart enforces that a new FixedPage is not started while another page is still open (_pageStartState already true). XPS document structure forbids nested pages, so a second RegisterPageStart without an intervening RegisterPageEnd throws XpsSerializationException(SR.ReachSerialization_FixedPageInPage).","triggerScenarios":"Calling RegisterPageStart twice without calling RegisterPageEnd, i.e. attempting to serialize a FixedPage inside an already-started FixedPage.","commonSituations":"Custom XPS writers that forget to close the previous page before starting the next; re-entrant serialization triggered by events or recursion; exception paths that skipped RegisterPageEnd leaving state stuck.","solutions":["Call RegisterPageEnd before starting a new page.","Audit the writer loop so each FixedPage start is paired with exactly one end.","Reset/recreate the serialization manager after an exception aborts a page mid-serialization."],"exampleFix":"// before\nmanager.RegisterPageStart();\nmanager.RegisterPageStart(); // throws\n// after\nmanager.RegisterPageStart();\n// ...serialize page content...\nmanager.RegisterPageEnd();\nmanager.RegisterPageStart();","handlingStrategy":"validation","validationCode":"// track page state yourself before calling\nbool pageOpen = _lastPageStarted && !_lastPageEnded;\nif (pageOpen) throw new InvalidOperationException(\"Previous FixedPage was not ended.\");","typeGuard":null,"tryCatchPattern":"try { manager.RegisterPageStart(); }\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"FixedPageInPage\")) { manager.RegisterPageEnd(); manager.RegisterPageStart(); }","preventionTips":["Always call RegisterPageEnd before the next RegisterPageStart","Use try/finally so exceptions cannot leave page state open","Keep one serialization manager instance per document"],"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-21T21:30:21.729Z"}