dotnet/wpf · error · XpsPackagingException

ReachPackaging_PrintTicketAlreadyCommitted

Error message

ReachPackaging_PrintTicketAlreadyCommitted

What it means

The PrintTicket setter of XpsFixedDocumentReaderWriter throws XpsPackagingException once the print ticket has already been committed (written) to the package. After Commit, the print ticket part is sealed per the XPS specification and cannot be replaced through this property. This prevents silently producing an inconsistent package.

Solutions

  1. Set the PrintTicket before calling CommitContent/Commit on the reader/writer.
  2. Create a new XpsFixedDocumentReaderWriter/package for the changed ticket instead of reusing the committed one.
  3. Restructure code so all print-ticket configuration is collected first, applied once, then committed.

Example fix

// before
fixedDocument.PrintTicket = ticket;
fixedDocument.CommitContent();
fixedDocument.PrintTicket = updatedTicket; // throws
// after
fixedDocument.PrintTicket = updatedTicket;
fixedDocument.CommitContent();
Defensive patterns

Strategy: validation

Validate before calling

if (fixedDocument is XpsFixedDocumentReaderWriter fd && fd.PrintTicket != null)
    /* ticket already set: verify it has not been committed yet before reassigning */;

Try / catch

try { fixedDocument.PrintTicket = ticket; }
catch (XpsPackagingException) { /* ticket committed: create new reader/writer with desired ticket */ }

Prevention

When it happens

Trigger: Assigning a non-null PrintTicket to the PrintTicket property of an XpsFixedDocumentReaderWriter after CommitContent has written the ticket to the underlying package part.

Common situations: Long-lived reader/writer objects reused across document writes; code that sets PrintTicket, calls Commit, then later applies user-changed print settings; batch XPS generation loops.

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/1d100c4af4a41aa9. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs:312

        /// <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 pages that are contained within
        /// this fixed document.

View on GitHub (pinned to 81131a70a4)