{"record":{"id":"591d07a0a464c34f","repo":"dotnet/wpf","slug":"sr-reachserialization-nofixedpages-xpsserializationmanager","errorCode":null,"errorMessage":"SR.ReachSerialization_NoFixedPages","messagePattern":"SR\\.ReachSerialization_NoFixedPages","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs","lineNumber":871,"sourceCode":"            _documentNumber += 1;\n            //\n            // Clearing the number of pages for this document\n            //\n            _pageNumber = 0;\n        }\n\n\n        internal\n        void\n        RegisterDocumentEnd()\n        {\n            //\n            // 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;","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs#L853-L889","documentation":"RegisterDocumentEnd validates that the FixedDocument being closed actually contains at least one page. An XPS FixedDocument with zero FixedPages is invalid, so when _pageNumber <= 0 the manager throws XpsSerializationException(SR.ReachSerialization_NoFixedPages) instead of emitting an empty document.","triggerScenarios":"Calling RegisterDocumentEnd without any RegisterPageStart/RegisterPageEnd pair in between — e.g. a paginator reports zero pages for a document, or page serialization was skipped/aborted.","commonSituations":"Printing empty collections or a DocumentPaginator whose GetPage count is 0; exceptions during the first page leaving the document empty; filtering logic that skips all pages but still closes the document.","solutions":["Ensure at least one page is serialized (RegisterPageStart/RegisterPageEnd) before RegisterDocumentEnd.","If content can legitimately be empty, emit a blank placeholder FixedPage rather than closing an empty document.","Fix the paginator so its page count matches the pages actually serialized.","On serialization failure, abort the whole document/sequence instead of calling RegisterDocumentEnd on a partial document."],"exampleFix":"// before\nmanager.RegisterDocumentStart();\n// no pages added\nmanager.RegisterDocumentEnd(); // throws\n// after\nmanager.RegisterDocumentStart();\nmanager.RegisterPageStart();\n// ... write blank/content page ...\nmanager.RegisterPageEnd();\nmanager.RegisterDocumentEnd();","handlingStrategy":"validation","validationCode":"if (pagesInCurrentDocument == 0)\n{\n    // emit a blank page or abort instead of ending an empty document\n    SerializeBlankPage(manager);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    manager.RegisterDocumentEnd();\n}\ncatch (System.Windows.Xps.XpsSerializationException ex) when (ex.Message.Contains(\"page\"))\n{\n    // document had no pages: emit a placeholder page or abort the document\n    SerializeBlankPage(manager);\n    manager.RegisterDocumentEnd();\n}","preventionTips":["Check the page count from your paginator before starting a document.","Always emit at least one FixedPage per FixedDocument, even for empty content.","On mid-document failure, abort the whole package instead of calling RegisterDocumentEnd."],"tags":["wpf","xps","state-machine","empty-document"],"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"}