dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_TargetNotPrintTicket

Error message

SR.ReachSerialization_TargetNotPrintTicket

What it means

Async counterpart of 3738: ReachPrintTicketSerializerAsync.SerializeObject throws XpsSerializationException(SR.ReachSerialization_TargetNotPrintTicket) when the supplied object is null or not a PrintTicket. On success it forwards the PrintTicket to XpsSerializationManagerAsync.PackagingPolicy.PersistPrintTicket.

Solutions

  1. Ensure a valid non-null PrintTicket reaches the async serializer
  2. Null-check the ticket before scheduling the async operation
  3. Use the appropriate async serializer for non-ticket objects
  4. Fix upstream PrintTicket creation/validation (e.g. PrintQueue.CreateXpsDocumentWriter flow)

Example fix

// before
printTicketSerializerAsync.SerializeObject(maybeNullTicket);
// after
if (maybeNullTicket is PrintTicket ticket)
    printTicketSerializerAsync.SerializeObject(ticket);
else
    throw new ArgumentException("A PrintTicket is required");
Defensive patterns

Strategy: validation

Validate before calling

if (obj is not PrintTicket) throw new ArgumentException("Async serializer requires a PrintTicket");

Type guard

bool IsPrintTicket(object o) => o is PrintTicket;

Try / catch

try { printTicketSerializerAsync.SerializeObject(obj); } catch (XpsSerializationException ex) { /* not a PrintTicket or disposed before async run */ }

Prevention

When it happens

Trigger: Async save path (called via PersistObjectData/SerializeObject) where the object to serialize is null or of a type other than PrintTicket, e.g. a FixedPage or document sequence.

Common situations: Async XPS pipelines where the print ticket failed to build and null flowed into the serializer; wrong serializer chosen for the node; race where the ticket was disposed/set to null before the async operation ran.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/f72e3e1938380741. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachPrintTicketSerializerAsync.cs:63

        /// </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);
            }

            ((XpsSerializationManagerAsync)SerializationManager).
            PackagingPolicy.PersistPrintTicket(printTicket);
        }

        #endregion Public Methods

        #region Internal Methods

        /// <summary>
        /// The main method that is called to serialize the PrintTicket
        /// and that is usually called from within the serialization manager
        /// when a node in the graph of objects is at a turn where it should
        /// be serialized.
        /// </summary>
        /// <param name="serializedProperty">
        /// The context of the property being serialized at this time and

View on GitHub (pinned to 81131a70a4)