{"record":{"id":"30ae141e008160ce","repo":"dotnet/wpf","slug":"packagepart-has-more-than-one-print-ticket-relationship","errorCode":null,"errorMessage":"PackagePart has more than one Print Ticket relationship.","messagePattern":"PackagePart has more than one Print Ticket relationship\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs","lineNumber":683,"sourceCode":"        {\n            PackagePart documentPart = _metroPackage.GetPart( documentUri );\n            PackagePart printTicketPart = null;\n\n            if( documentPart == null )\n            {\n              throw new InvalidDataException(SR.ReachPackaging_InvalidDocUri);\n            }\n\n            string printTicketRelName =\n                XpsS0Markup.PrintTicketRelationshipName;\n            PackageRelationship printTicketRel = null;\n\n            foreach (PackageRelationship rel in\n                     documentPart.GetRelationshipsByType(printTicketRelName))\n            {\n                if (printTicketRel != null)\n                {\n                    throw new InvalidDataException(SR.ReachPackaging_MoreThanOnePrintTicketPart);\n                }\n\n                printTicketRel = rel;\n            }\n            if (printTicketRel != null)\n            {\n                Uri printTicketUri = PackUriHelper.ResolvePartUri(documentUri, printTicketRel.TargetUri);\n                printTicketPart = _metroPackage.GetPart(printTicketUri);\n            }\n            return printTicketPart;\n        }\n\n        public\n        PackagePart\n        AddDocumentPropertiesPart()\n        {\n            //\n            // If a part exists return the existing part","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs#L665-L701","documentation":"GetPrintTicketPart allows at most one Print Ticket relationship per document part. When a second relationship of type PrintTicketRelationshipName is encountered during enumeration it throws InvalidDataException SR.ReachPackaging_MoreThanOnePrintTicketPart, since XPS semantics require a single print ticket per document.","triggerScenarios":"Reading a package where the document part has multiple relationships of XpsS0Markup.PrintTicketRelationshipName — e.g. a ticket added per-page plus per-document under the same relationship type on one part, or a producer appending without deduplication.","commonSituations":"Custom merge/export tools that attach a print ticket to every level but anchor them on the same part; generators writing a new ticket each time settings change instead of replacing the relationship; corrupted packages from interrupted writes.","solutions":["Open the package and remove redundant PrintTicket relationships so only one remains per document part.","Update the writing code to delete the existing print ticket relationship before adding a new one.","Re-export the document through the standard WPF XPS save path to rebuild a conforming relationship set.","Validate the package (OPC conformance check) before loading if it comes from an external producer."],"exampleFix":"// before\nforeach (var ticket in tickets)\n    documentPart.CreateRelationship(ticketUri, TargetMode.Internal, XpsS0Markup.PrintTicketRelationshipName);\n// after\nvar existing = documentPart.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).ToList();\nforeach (var rel in existing) documentPart.DeleteRelationship(rel.Id);\ndocumentPart.CreateRelationship(ticketUri, TargetMode.Internal, XpsS0Markup.PrintTicketRelationshipName);","handlingStrategy":"validation","validationCode":"int ptCount = documentPart.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).Count();\nif (ptCount > 1) throw new InvalidDataException(\"Package contains more than one Print Ticket relationship\");","typeGuard":"bool HasSinglePrintTicket(PackagePart p) => p.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).Count() <= 1;","tryCatchPattern":"try { return xpsManager.GetPrintTicketPart(documentUri); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"Print Ticket\")) { /* repair package by removing extra ticket relationships, then retry */ }","preventionTips":["When updating a print ticket, delete the previous relationship first.","Keep print tickets attached at the correct level only (document or page, not both on one part).","Validate relationship cardinality in your package-writing unit tests."],"tags":["wpf","xps","printticket","corrupt-package"],"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"}