dotnet/wpf · error · XpsPackagingException
Property is not a valid instance of PrintTicket.
Error message
Property is not a valid instance of PrintTicket.
What it means
The PrintTicket setter of XpsFixedDocumentSequenceReaderWriter throws XpsPackagingException (ReachPackaging_NotAPrintTicket) when the assigned value's runtime type is not exactly System.Printing.PrintTicket. Subclasses and foreign types are rejected so the ticket can be safely cloned (_printTicket = value.Clone()) and serialized.
Solutions
- Assign an exact System.Printing.PrintTicket instance.
- Round-trip a subclass through its XML (GetXmlStream) into a base PrintTicket before assigning.
- Correct the producing code (binder, deserializer, DI factory) to emit the exact type.
Example fix
// before object value = settings["Ticket"]; seq.PrintTicket = (PrintTicketSubclass)value; // throws // after var exact = new PrintTicket(((PrintTicket)value).GetXmlStream()); seq.PrintTicket = exact;
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 { seq.PrintTicket = ticket; }
catch (XpsPackagingException) { seq.PrintTicket = new PrintTicket(ticket.GetXmlStream()); } Prevention
- Pass only exact PrintTicket instances to XPS APIs.
- Normalize tickets to the base type at API boundaries.
- Test any code path that produces tickets dynamically.
When it happens
Trigger: Assigning a PrintTicket subclass or a wrong-typed object to XpsFixedDocumentSequenceReaderWriter.PrintTicket; value != null but value.GetType() != typeof(PrintTicket).
Common situations: Derived PrintTicket classes from custom printing frameworks; loosely-typed values from configuration or UI binding; deserializers returning dynamic/subclass instances.
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.
- ReachPackaging_NotAPrintTicket
- 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/d2bae4c7f7efc89d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentSequenceReaderWriter.cs:244
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 documents that are contained within
/// this document sequence.
/// </summary>
/// <value>
/// Value is a Collection containing IXpsFixedDocumentReader interfaces.
/// </value>
/// <remarks>View on GitHub (pinned to 81131a70a4)