dotnet/wpf · error · XpsPackagingException
ReachPackaging_NotAPrintTicket
Error message
ReachPackaging_NotAPrintTicket
What it means
The PrintTicket setter of XpsFixedDocumentReaderWriter throws XpsPackagingException when the assigned value is not exactly of type System.Printing.PrintTicket. The check uses value.GetType().Equals(typeof(PrintTicket)), so even PrintTicket subclasses are rejected. This ensures the stored ticket can be cloned and serialized correctly.
Solutions
- Assign an instance whose runtime type is exactly System.Printing.PrintTicket.
- If you have a subclass, round-trip its settings through GetXmlStream into a new base PrintTicket before assigning.
- Fix the source of the object (settings store/deserializer) to return the exact PrintTicket type.
Example fix
// before MyPrintTicket custom = LoadTicket(); fixedDocument.PrintTicket = custom; // throws: not exactly PrintTicket // after var ticket = new PrintTicket(custom.GetXmlStream()); fixedDocument.PrintTicket = ticket;
Defensive patterns
Strategy: type-guard
Validate before calling
if (value != null && value.GetType() != typeof(PrintTicket))
value = new PrintTicket(((PrintTicket)value).GetXmlStream()); Type guard
bool IsExactPrintTicket(object v) => v is PrintTicket && v.GetType() == typeof(PrintTicket);
Try / catch
try { fixedDocument.PrintTicket = ticket; }
catch (XpsPackagingException) { fixedDocument.PrintTicket = new PrintTicket(ticket.GetXmlStream()); } Prevention
- Avoid PrintTicket subclasses when passing tickets to XPS APIs.
- Normalize any ticket to base PrintTicket at the boundary of your code.
- Assert types in unit tests for settings that supply tickets.
When it happens
Trigger: Assigning an object to XpsFixedDocumentReaderWriter.PrintTicket whose runtime type is a PrintTicket subclass or an entirely different type (e.g. from a loosely-typed settings store or deserializer).
Common situations: Settings frameworks returning derived ticket types; reflection- or DI-based construction of tickets; code refactored to a custom PrintTicket subclass for extra state.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Property is not a valid instance of PrintTicket.
- Property is not a valid instance of PrintTicket.
- PackagePart has more than one Print Ticket relationship.
- PrintTicket was already committed.
- PrintTicket was already committed.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0e58cbeadad61f86.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs:316
get
{
if( _printTicket == null )
{
_printTicket = CurrentXpsManager.EnsurePrintTicket( Uri );
}
return _printTicket;
}
set
{
if(value != null)
{
if (_isPrintTicketCommitted)
{
throw new XpsPackagingException(SR.ReachPackaging_PrintTicketAlreadyCommitted);
}
if (!value.GetType().Equals(typeof(PrintTicket)))
{
throw new XpsPackagingException(SR.ReachPackaging_NotAPrintTicket);
}
_printTicket = value.Clone();
}
else
{
_printTicket = null;
}
}
}
/// <summary>
/// Gets a collection of all fixed pages that are contained within
/// this fixed document.
/// </summary>
/// <value>
/// Value is a Collection containing IXpsFixedPageReader interfaces.
/// </value>View on GitHub (pinned to 81131a70a4)