dotnet/wpf · error · XpsPackagingException

Current DocumentSequence, FixedDocument, or FixedPage not…

Error message

Current DocumentSequence, FixedDocument, or FixedPage not completed.

What it means

XpsFixedDocumentReaderWriter.AddFixedPage throws XpsPackagingException (ReachPackaging_PanelOrSequenceAlreadyOpen: 'Current DocumentSequence, FixedDocument, or FixedPage not completed.') when a page is already being written. The XPS writing model allows only one open page at a time; the previous page must be committed before a new one is added. The source guards on _currentPage != null.

Solutions

  1. Call Commit (and Close/dispose) on the current XpsFixedPageReaderWriter before calling AddFixedPage again.
  2. Ensure exception handlers commit or abandon the in-flight page so _currentPage is cleared.
  3. Wrap each page write in try/finally that disposes the page writer.
  4. Serialize page writing on one thread; do not call AddFixedPage concurrently.

Example fix

// before
for (var i = 0; i < pages; i++) { doc.AddFixedPage(); } // second call throws
// after
for (var i = 0; i < pages; i++) {
    var page = doc.AddFixedPage();
    try { WritePageContent(page); page.Commit(); }
    finally { page.Close(); }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// only call when no page is open
if (currentPageWriter != null && !currentPageWriterCommitted)
    return; // or commit first

Try / catch

try { var page = doc.AddFixedPage(); /* write, commit */ }
catch (XpsPackagingException ex) when (ex.Message.Contains("not completed")) { /* commit outstanding page then retry */ }

Prevention

When it happens

Trigger: Calling AddFixedPage while the XpsFixedPageReaderWriter returned by a previous AddFixedPage call is still active (its Commit/Close not yet called).

Common situations: Looped page-generation code that forgets to commit each page; exception paths that skip page commit leaving _currentPage set; concurrent writes from multiple threads.

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/4f461888e6b4de9d. Report an issue: GitHub.

Appendix: source

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

        /// </summary>
        /// <returns>
        /// Returns an interface to the newly created fixed page.
        /// </returns>
        /// <exception cref="ObjectDisposedException">The FixedDocument has already been disposed</exception>
        /// <exception cref="SR.ReachPackaging_PanelOrSequenceAlreadyOpen">FixedPage is not completed.</exception>
        public
        IXpsFixedPageWriter
        AddFixedPage(
            )
        {
            ObjectDisposedException.ThrowIf(_metroPart is null || CurrentXpsManager.MetroPackage is null, typeof(XpsFixedDocumentReaderWriter));

            //
            // Only one page can be created/written at a time.
            //
            if (null != _currentPage)
            {
                throw new XpsPackagingException(SR.ReachPackaging_PanelOrSequenceAlreadyOpen);
            }


            _linkTargetStream = new List<String>();

            //
            // Create the part and writer
            //
            PackagePart metroPart = this.CurrentXpsManager.GenerateUniquePart(XpsS0Markup.FixedPageContentType);
            XpsFixedPageReaderWriter fixedPage = new XpsFixedPageReaderWriter(CurrentXpsManager, this, metroPart, _linkTargetStream, _pagesWritten + 1);

            //
            // Make the new page the current page
            //
            _currentPage = fixedPage;


            //Here we used to add the fixed page to _pageCache, but _pageCache is never accessed if this object was created as an IXpsFixedDocumentWriter.

View on GitHub (pinned to 81131a70a4)