dotnet/wpf · error · InvalidDataException
PackagePart has more than one Print Ticket relationship.
Error message
PackagePart has more than one Print Ticket relationship.
What it means
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.
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.
Example fix
// before
foreach (var ticket in tickets)
documentPart.CreateRelationship(ticketUri, TargetMode.Internal, XpsS0Markup.PrintTicketRelationshipName);
// after
var existing = documentPart.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).ToList();
foreach (var rel in existing) documentPart.DeleteRelationship(rel.Id);
documentPart.CreateRelationship(ticketUri, TargetMode.Internal, XpsS0Markup.PrintTicketRelationshipName); Defensive patterns
Strategy: validation
Validate before calling
int ptCount = documentPart.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).Count();
if (ptCount > 1) throw new InvalidDataException("Package contains more than one Print Ticket relationship"); Type guard
bool HasSinglePrintTicket(PackagePart p) => p.GetRelationshipsByType(XpsS0Markup.PrintTicketRelationshipName).Count() <= 1;
Try / catch
try { return xpsManager.GetPrintTicketPart(documentUri); }
catch (InvalidDataException ex) when (ex.Message.Contains("Print Ticket")) { /* repair package by removing extra ticket relationships, then retry */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Document has more than one Signature Definition…
- Document has more than one Thumbnail relationship.
- Package must contain an XPS PackagePart.
- PrintTicket was already committed.
- PrintTicket was already committed.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/30ae141e008160ce.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs:683
{
PackagePart documentPart = _metroPackage.GetPart( documentUri );
PackagePart printTicketPart = null;
if( documentPart == null )
{
throw new InvalidDataException(SR.ReachPackaging_InvalidDocUri);
}
string printTicketRelName =
XpsS0Markup.PrintTicketRelationshipName;
PackageRelationship printTicketRel = null;
foreach (PackageRelationship rel in
documentPart.GetRelationshipsByType(printTicketRelName))
{
if (printTicketRel != null)
{
throw new InvalidDataException(SR.ReachPackaging_MoreThanOnePrintTicketPart);
}
printTicketRel = rel;
}
if (printTicketRel != null)
{
Uri printTicketUri = PackUriHelper.ResolvePartUri(documentUri, printTicketRel.TargetUri);
printTicketPart = _metroPackage.GetPart(printTicketUri);
}
return printTicketPart;
}
public
PackagePart
AddDocumentPropertiesPart()
{
//
// If a part exists return the existing partView on GitHub (pinned to 81131a70a4)