dotnet/wpf · error · XpsSerializationException
SR.ReachSerialization_TargetNotPrintTicket
Error message
SR.ReachSerialization_TargetNotPrintTicket
What it means
ReachPrintTicketSerializer.SerializeObject throws XpsSerializationException(SR.ReachSerialization_TargetNotPrintTicket) when the object passed for serialization is null or not a PrintTicket (it is cast/as-cast to PrintTicket and null-checked). This serializer only persists PrintTicket objects; anything else — including null — is rejected with this meaningful exception.
Solutions
- Pass a non-null PrintTicket instance to SerializeObject
- Check upstream construction — a failed PrintTicket creation silently returned null
- Use the correct serializer for other object types (FixedPage/FixedDocument serializers)
- Guard with a type check before invoking the serializer
Example fix
// before
printTicketSerializer.SerializeObject(queue); // not a PrintTicket
// after
if (target is PrintTicket pt)
printTicketSerializer.SerializeObject(pt);
else
throw new ArgumentException("Expected a PrintTicket"); Defensive patterns
Strategy: validation
Validate before calling
if (obj is not PrintTicket pt) throw new ArgumentException("Expected PrintTicket"); Type guard
bool IsPrintTicket(object o) => o is PrintTicket;
Try / catch
try { printTicketSerializer.SerializeObject(obj); } catch (XpsSerializationException ex) { /* target was not a PrintTicket */ } Prevention
- Null-check PrintTicket construction results upstream
- Dispatch to serializers by exact type
- Never pass null into serializer entry points
When it happens
Trigger: Calling ReachPrintTicketSerializer.SerializeObject(obj) where obj is null, or is not a PrintTicket (e.g. a PrintQueue, a raw XML stream, or another document part).
Common situations: Manual XPS packaging code that passes the wrong part of the document to the print-ticket serializer; a print ticket failed to construct upstream and null propagated; confusion between PrintTicket and FixedPage/FixedDocument serializers.
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
- SR.ReachSerialization_TargetNotPrintTicket
- SR.MustBeOfType
- SR.MustBeOfType
- SR.ReachSerialization_WrongPropertyTypeForPageContent
- SR.ReachSerialization_WrongPropertyTypeForPageContent
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6f98c03f7db305ef.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachPrintTicketSerializer.cs:64
/// </summary>
/// <param name="serializedObject">
/// Instance of object to be serialized.
/// </param>
public
override
void
SerializeObject(
object serializedObject
)
{
PrintTicket printTicket = serializedObject as PrintTicket;
if (printTicket == null)
{
//
// Throw a meaningful exception
//
throw new XpsSerializationException(SR.ReachSerialization_TargetNotPrintTicket);
}
// The new class XpsOMSerializationManager now also interacts with this class
// the cast below is shorthand for cast to either XpsSerializationManager or XpsOMSerializationManager
// we want this to throw an InvalidCastException if it fails to mantain compatibility.
if ((IXpsSerializationManager)SerializationManager != null)
{
SerializationManager.
PackagingPolicy.PersistPrintTicket(printTicket);
}
}
#endregion Public Methods
#region Internal Methods
/// <summary>
/// The main method that is called to serialize the PrintTicketView on GitHub (pinned to 81131a70a4)