{"record":{"id":"a4cb314e6c3ef9ef","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloadermorethanoneprintticketpart","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderMoreThanOnePrintTicketPart","messagePattern":"SR\\.XpsValidatingLoaderMoreThanOnePrintTicketPart","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":550,"sourceCode":"                                }\n                    );\n        }\n\n        public override void ValidateRelationships(Package package, Uri packageUri, Uri partUri, ContentType mimeType)\n        {\n            PackagePart part = package.GetPart(partUri);\n            PackageRelationshipCollection checkRels;\n            int count;\n\n            // Can only have 0 or 1 PrintTicket per FDS, FD or FP part\n            checkRels = part.GetRelationshipsByType(_printTicketRel);\n            count = 0;\n            foreach (PackageRelationship rel in checkRels)\n            {\n                count++;\n                if (count > 1)\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOnePrintTicketPart);\n                }\n\n                // Also check for existence and type\n                Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                PackagePart targetPart = package.GetPart(targetUri);\n\n                if (!_printTicketContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderPrintTicketHasIncorrectType);\n                }\n            }\n\n            checkRels = part.GetRelationshipsByType(_thumbnailRel);\n            count = 0;\n            foreach (PackageRelationship rel in checkRels)\n            {","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L532-L568","documentation":"Per the XPS spec, a FixedDocumentSequence, FixedDocument, or FixedPage part may have at most one PrintTicket relationship. XpsS0FixedPageSchema.ValidateRelationships counts relationships of the PrintTicket type on the part and throws FileFormatException as soon as a second one is found.","triggerScenarios":"Opening an XPS package where a FixedDocumentSequence/FixedDocument/FixedPage part has two or more package relationships of type http://schemas.microsoft.com/xps/2005/06/required-resource:PrintTicket (or the printticket rel type); validation enumerates part.GetRelationshipsByType and trips at count>1.","commonSituations":"Tools merging XPS documents or applying job-level and document-level print tickets by blindly adding relationships; package-editing scripts that append a PrintTicket relationship without removing the existing one; round-tripping through libraries that duplicate relationships.","solutions":["Remove duplicate PrintTicket relationships so each FDS/FD/FP part has at most one (delete extra rels via part.DeleteRelationship or rebuild the package).","Keep a single job-level PrintTicket at the FixedDocumentSequence level and remove per-document/per-page duplicates.","Rebuild the relationship list programmatically before loading: enumerate GetRelationshipsByType and prune to one.","Re-export the XPS from the original producer after fixing ticket attachment logic."],"exampleFix":"// before\npart.CreateRelationship(printTicketUri, TargetMode.Internal, printTicketRelType); // adds a second ticket rel\n// after\nif (!part.GetRelationshipsByType(printTicketRelType).Any())\n    part.CreateRelationship(printTicketUri, TargetMode.Internal, printTicketRelType);","handlingStrategy":"validation","validationCode":"const string printTicketRel = \"http://schemas.microsoft.com/xps/2005/06/required-resource:printticket\";\nvar ticketRels = fixedPart.GetRelationshipsByType(printTicketRel).ToList();\nif (ticketRels.Count > 1)\n    ticketRels.Skip(1).ToList().ForEach(r => fixedPart.DeleteRelationship(r.Id));","typeGuard":"static bool HasSinglePrintTicket(PackagePart part, string relType) =>\n    part.GetRelationshipsByType(relType).Cast<PackageRelationship>().Take(2).Count() <= 1;","tryCatchPattern":"try { loader.Load(packageStream); }\ncatch (FileFormatException ex) { // duplicate PrintTicket rel: open package read-write, prune rels, retry once\n    PruneDuplicatePrintTicketRels(packageStream); loader.Load(packageStream); }","preventionTips":["Before adding a PrintTicket relationship, check GetRelationshipsByType for an existing one.","Prefer one job-level ticket on the FixedDocumentSequence over per-part tickets.","Never merge packages by blindly copying relationships."],"tags":["xps","printticket","package-relationships","validation"],"backgroundTag":"schema-validation-failed","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"}