{"record":{"id":"1d100c4af4a41aa9","repo":"dotnet/wpf","slug":"reachpackaging-printticketalreadycommitted","errorCode":null,"errorMessage":"ReachPackaging_PrintTicketAlreadyCommitted","messagePattern":"ReachPackaging_PrintTicketAlreadyCommitted","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs","lineNumber":312,"sourceCode":"        /// <exception cref=\"SR.ReachPackaging_PrintTicketAlreadyCommitted\">PrintTicket has already been committed.</exception>\n        /// <exception cref=\"SR.ReachPackaging_NotAPrintTicket\">Property is not a valid PrintTicket instance.</exception>\n        public PrintTicket PrintTicket\n        {\n            get\n            {\n                if( _printTicket == null )\n                {\n                    _printTicket = CurrentXpsManager.EnsurePrintTicket( Uri );\n                }\n                return _printTicket;\n            }\n            set\n            {\n                if(value != null)\n                {\n                    if (_isPrintTicketCommitted)\n                    {\n                        throw new XpsPackagingException(SR.ReachPackaging_PrintTicketAlreadyCommitted);\n                    }\n                    if (!value.GetType().Equals(typeof(PrintTicket)))\n                    {\n                        throw new XpsPackagingException(SR.ReachPackaging_NotAPrintTicket);\n                    }\n\n                    _printTicket = value.Clone();\n                }\n                else\n                {\n                    _printTicket = null;\n                }\n            }\n        }\n\n        /// <summary>\n        /// Gets a collection of all fixed pages that are contained within\n        /// this fixed document.","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs#L294-L330","documentation":"The PrintTicket setter of XpsFixedDocumentReaderWriter throws XpsPackagingException once the print ticket has already been committed (written) to the package. After Commit, the print ticket part is sealed per the XPS specification and cannot be replaced through this property. This prevents silently producing an inconsistent package.","triggerScenarios":"Assigning a non-null PrintTicket to the PrintTicket property of an XpsFixedDocumentReaderWriter after CommitContent has written the ticket to the underlying package part.","commonSituations":"Long-lived reader/writer objects reused across document writes; code that sets PrintTicket, calls Commit, then later applies user-changed print settings; batch XPS generation loops.","solutions":["Set the PrintTicket before calling CommitContent/Commit on the reader/writer.","Create a new XpsFixedDocumentReaderWriter/package for the changed ticket instead of reusing the committed one.","Restructure code so all print-ticket configuration is collected first, applied once, then committed."],"exampleFix":"// before\nfixedDocument.PrintTicket = ticket;\nfixedDocument.CommitContent();\nfixedDocument.PrintTicket = updatedTicket; // throws\n// after\nfixedDocument.PrintTicket = updatedTicket;\nfixedDocument.CommitContent();","handlingStrategy":"validation","validationCode":"if (fixedDocument is XpsFixedDocumentReaderWriter fd && fd.PrintTicket != null)\n    /* ticket already set: verify it has not been committed yet before reassigning */;","typeGuard":null,"tryCatchPattern":"try { fixedDocument.PrintTicket = ticket; }\ncatch (XpsPackagingException) { /* ticket committed: create new reader/writer with desired ticket */ }","preventionTips":["Set PrintTicket before any Commit call.","Do not reuse committed reader/writer objects.","Collect user print settings before starting the write pipeline."],"tags":["wpf","xps","printticket","invalid-state"],"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"}