dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_FixedPageInPage

Error message

SR.ReachSerialization_FixedPageInPage

What it means

IXpsSerializationManager.RegisterPageStart enforces that pages cannot nest: if a FixedPage is already open (_pageStartState), starting another page throws XpsSerializationException(SR.ReachSerialization_FixedPageInPage). XPS requires each FixedPage to be ended before the next begins.

Solutions

  1. Always pair RegisterPageStart with RegisterPageEnd before starting the next page (try/finally around page serialization).
  2. On page-level failure, call RegisterPageEnd (or abort the whole document) before retrying, never call RegisterPageStart again directly.
  3. Guard the page-start call with a local 'pageOpen' flag in your serializer to detect double-entry.
  4. Use XpsDocumentWriter with a DocumentPaginator to avoid manual page lifecycle management.

Example fix

// before
manager.RegisterPageStart();
manager.RegisterPageStart(); // nested page
// after
manager.RegisterPageStart();
// ... serialize page ...
manager.RegisterPageEnd();
manager.RegisterPageStart(); // next page
Defensive patterns

Strategy: try-catch

Validate before calling

if (pageOpen)
    throw new InvalidOperationException("RegisterPageStart called while another FixedPage is open; call RegisterPageEnd first.");

Try / catch

try
{
    manager.RegisterPageStart();
}
catch (System.Windows.Xps.XpsSerializationException ex) when (ex.Message.Contains("page"))
{
    // a page is already open: end it before starting the new one
    manager.RegisterPageEnd();
    manager.RegisterPageStart();
}

Prevention

When it happens

Trigger: Calling RegisterPageStart twice without RegisterPageEnd — duplicate page-start callbacks, a paginator that re-enters page production, or a retry path that restarts the current page without ending it first.

Common situations: Custom XPS writers handling WriteAsync callbacks that fire twice; retry logic around failing pages missing cleanup; re-entrancy from print-events triggering a second page start.

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/7579090dfdac22c4. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs:884

            // It is invalid to have a document with no fixed pages
            // If no fixed pages have been searialzed throw
            //
            if( _pageNumber <= 0 )
            {
                throw new XpsSerializationException(SR.ReachSerialization_NoFixedPages);
            }
            //
            // Exiting Document  Started state
            //
            _documentStartState = false;
        }

        void
        IXpsSerializationManager.RegisterPageStart()
        {
            if( _pageStartState )
            {
                throw new XpsSerializationException(SR.ReachSerialization_FixedPageInPage);
            }
            //
            // Entering Page  Started state
            //
            _pageStartState = true;
            //
            // Increment the number of documents serialized
            //
            _pageNumber += 1;
        }


        void
        IXpsSerializationManager.RegisterPageEnd()
        {
            //
            // Exiting Page  Started state
            //

View on GitHub (pinned to 81131a70a4)