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
XpsPackagingException thrown from the PrintTicket setter of XpsFixedPageReaderWriter when the assigned value's runtime type is not exactly System.Printing.PrintTicket (the check uses GetType().Equals, so subclasses fail too). The writer requires an exact PrintTicket instance because it clones the ticket to snapshot its settings. It guarantees the stored object exposes the full PrintTicket surface.
Solutions
- Assign an instance of exactly System.Printing.PrintTicket; do not subclass it.
- If you have a derived type, construct a new PrintTicket and copy needed properties (e.g. via GetXmlStream/Build a fresh ticket).
- Verify assembly binding — ensure only one version of the WPF/Printing assemblies loads in the process.
- Check the value's actual type at the assignment site (value.GetType()) when data comes from reflection or deserialization.
Example fix
// before
class MyTicket : PrintTicket { } // subclass
pageWriter.PrintTicket = new MyTicket(...); // throws
// after
PrintTicket ticket = new PrintTicket(printQueue.DefaultPrintTicket.GetXmlStream());
ticket.PageOrientation = PageOrientation.Landscape;
pageWriter.PrintTicket = ticket; // exact type Defensive patterns
Strategy: type-guard
Validate before calling
// Verify exact runtime type before assigning
if (value.GetType() != typeof(System.Printing.PrintTicket))
throw new ArgumentException("PrintTicket must be exactly System.Printing.PrintTicket", nameof(value)); Type guard
static bool IsExactPrintTicket(object value) =>
value is PrintTicket && value.GetType() == typeof(PrintTicket); Try / catch
try
{
pageWriter.PrintTicket = candidate;
}
catch (XpsPackagingException ex) when (ex.Message.Contains("PrintTicket"))
{
// rebuild a genuine PrintTicket from XML
var xml = GetTicketXml(candidate);
pageWriter.PrintTicket = new PrintTicket(new MemoryStream(xml));
} Prevention
- Never subclass PrintTicket; extend behavior externally.
- Build tickets with new PrintTicket(Stream) from ticket XML to guarantee the exact type.
- Check assembly binding for duplicate WPF/Printing assembly versions loading into the AppDomain.
- When data arrives via reflection/deserialization, assert value.GetType() == typeof(PrintTicket) before use.
When it happens
Trigger: Assigning any object that is not exactly PrintTicket to pageWriter.PrintTicket — e.g. a subclass of PrintTicket, an object from a different assembly/version of ReachFramework/PresentationCore, or an incorrectly cast value from deserialization.
Common situations: Custom PrintTicket-derived classes used for extra metadata; DLL version mismatches causing two distinct PrintTicket types in one AppDomain; dynamic/late-bound assignment from config that yields System.Object at runtime.
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/9fe12cbe20bae5c0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs:513
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 reference to the XmlWriter for the Metro part
/// that represents this fixed page within the package.
/// </summary>
public XmlWriter XmlWriter
{
getView on GitHub (pinned to 81131a70a4)