dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_FixedDocumentInPage

Error message

SR.ReachSerialization_FixedDocumentInPage

What it means

RegisterDocumentStart also rejects starting a FixedDocument while a FixedPage is still open (_pageStartState true). A document may not begin inside a page, so XpsSerializationException(SR.ReachSerialization_FixedDocumentInPage) is thrown.

Solutions

  1. Call RegisterPageEnd before RegisterDocumentStart.
  2. Enforce the canonical call order: DocumentSequenceStart → DocumentStart → PageStart → PageEnd → DocumentEnd → SequenceEnd.
  3. Check _pageStartState-equivalent logic in your wrapper so documents never start inside pages.

Example fix

// before
manager.RegisterPageStart();
manager.RegisterDocumentStart(); // throws
// after
manager.RegisterPageStart();
manager.RegisterPageEnd();
manager.RegisterDocumentStart();
Defensive patterns

Strategy: validation

Validate before calling

bool pageOpen = _pageStarted && !_pageEnded;
if (pageOpen) throw new InvalidOperationException("Cannot start a document inside an open page.");

Try / catch

try { manager.RegisterDocumentStart(); }
catch (XpsSerializationException ex) when (ex.Message.Contains("FixedDocumentInPage")) { manager.RegisterPageEnd(); manager.RegisterDocumentStart(); }

Prevention

When it happens

Trigger: Calling RegisterDocumentStart after RegisterPageStart but before RegisterPageEnd — starting a document nested inside an open page.

Common situations: Incorrect ordering of Register* calls in custom XPS writers (page opened, then document started); recursion into document serialization from within page content generation.

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/85410dbeebd4e0d9. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs:704

            // If no fixed documents have been searialzed throw
            //
            if (_documentNumber <= 0)
            {
                throw new XpsSerializationException(SR.ReachSerialization_NoFixedDocuments);
            }
        }

        internal
        void
        RegisterDocumentStart()
        {
            if( _documentStartState )
            {
                throw new XpsSerializationException(SR.ReachSerialization_FixedDocumentInDocument);
            }
            if( _pageStartState)
            {
                throw new XpsSerializationException(SR.ReachSerialization_FixedDocumentInPage);
            }
            //
            // Entering Document  Started state
            //
            _documentStartState = true;
            //
            // Increment the number of documents serialized
            //
            _documentNumber += 1;
            //
            // Clearing the number of pages for this document
            //
            _pageNumber = 0;
        }

        internal
        void
        RegisterDocumentEnd()

View on GitHub (pinned to 81131a70a4)