{"record":{"id":"f0cccb72c2423a11","repo":"dotnet/wpf","slug":"currentfixedpagewriter-uninitialized","errorCode":null,"errorMessage":"CurrentFixedPageWriter uninitialized","messagePattern":"CurrentFixedPageWriter uninitialized","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs","lineNumber":344,"sourceCode":"        /// </summary>\n        public\n        override\n        void\n        RelateRestrictedFontToCurrentDocument(\n            Uri targetUri\n            )\n        {\n            return;\n        }\n\n        public\n        override\n        XmlWriter\n        AcquireXmlWriterForPage()\n        {\n            if (_currentFixedPageXmlWriter == null)\n            {\n                throw new InvalidOperationException(\"CurrentFixedPageWriter uninitialized\");\n            }\n            return _currentPageContentXmlWriter;\n        }\n\n        public\n        override\n        XmlWriter\n        AcquireXmlWriterForResourceDictionary()\n        {\n            if (_currentFixedPageXmlWriter == null)\n            {\n                throw new InvalidOperationException(\"CurrentFixedPageWriter uninitialized\");\n            }\n            return _currentResourceXmlWriter;\n        }\n\n        public\n        override","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs#L326-L362","documentation":"AcquireXmlWriterForPage returns the page-content XmlWriter, but requires the current fixed-page writer to have been initialized first via AcquireXmlWriterForFixedPage. If _currentFixedPageXmlWriter is null (no page is open), InvalidOperationException(\"CurrentFixedPageWriter uninitialized\") is thrown.","triggerScenarios":"Calling AcquireXmlWriterForPage outside of an open FixedPage — i.e. before AcquireXmlWriterForFixedPage or after ReleaseXmlWriterForFixedPage closed the page.","commonSituations":"Custom serialization code acquiring page-content writers in the wrong order; writing after page release; calling the policy from a different code path than the standard XpsSerializationManager flow.","solutions":["Call AcquireXmlWriterForFixedPage before AcquireXmlWriterForPage.","Check the page writer is still open (page not yet released) before acquiring page-content writers.","Follow the standard lifecycle: acquire page -> acquire page content/resources -> write -> release all -> release page."],"exampleFix":"// before\nXmlWriter w = policy.AcquireXmlWriterForPage(); // throws: no page open\n// after\npolicy.AcquireXmlWriterForFixedPage();\nXmlWriter w = policy.AcquireXmlWriterForPage();\n... w.WriteRaw(...);\npolicy.ReleaseXmlWriterForPage();\npolicy.ReleaseXmlWriterForFixedPage();","handlingStrategy":"validation","validationCode":"if (!pageOpen) throw new InvalidOperationException(\"Open a FixedPage (AcquireXmlWriterForFixedPage) before AcquireXmlWriterForPage\");","typeGuard":"static bool PageOpen(XpsOMPackagingPolicy p) => p.CurrentFixedPageUri != null;","tryCatchPattern":"try { var w = policy.AcquireXmlWriterForPage(); }\ncatch (InvalidOperationException ex) { log(\"Page writer uninitialized — wrong lifecycle order\", ex); }","preventionTips":["Always call AcquireXmlWriterForFixedPage first","Follow the standard serialization lifecycle order","Do not write page content after releasing the page","Check CurrentFixedPageUri as a liveness signal"],"tags":["wpf","xps","serialization","lifecycle"],"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"}