dotnet/wpf · error · XpsPackagingException

PrintTicket was already committed.

Error message

PrintTicket was already committed.

What it means

The PrintTicket setter of XpsFixedDocumentSequenceReaderWriter throws XpsPackagingException (ReachPackaging_PrintTicketAlreadyCommitted) when a non-null ticket is assigned after the print ticket was already committed to the package. Once committed, the sequence-level ticket part is sealed and cannot be replaced via this property.

Solutions

  1. Assign the PrintTicket before committing the document sequence.
  2. If settings changed after commit, recreate the XpsFixedDocumentSequenceWriter/package with the new ticket.
  3. Collect all job print settings up front, set once, then commit.

Example fix

// before
seq.PrintTicket = ticket;
seq.CommitContent();
seq.PrintTicket = newTicket; // throws
// after
seq.PrintTicket = newTicket;
seq.CommitContent();
Defensive patterns

Strategy: validation

Validate before calling

if (seqTicketSet && seqCommitted) throw new Exception("PrintTicket already committed; recreate the sequence writer.");

Try / catch

try { seq.PrintTicket = newTicket; }
catch (XpsPackagingException) { /* ticket committed: recreate package/sequence writer */ }

Prevention

When it happens

Trigger: Setting PrintTicket on XpsFixedDocumentSequenceReaderWriter after CommitContent/Commit wrote the sequence's ticket part.

Common situations: Document-sequence-level print settings applied after generation began; reusing one sequence writer for multiple jobs; late user changes to print options in a batch pipeline.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentSequenceReaderWriter.cs:240

        /// <exception cref="SR.ReachPackaging_PrintTicketAlreadyCommitted">PrintTicket has already been committed.</exception>
        /// <exception cref="SR.ReachPackaging_NotAPrintTicket">Property is not a valid PrintTicket instance.</exception>
        public PrintTicket PrintTicket
        {
            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>

View on GitHub (pinned to 81131a70a4)