dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_FixedPageInPage

Error message

SR.ReachSerialization_FixedPageInPage

What it means

RegisterPageStart enforces that a new FixedPage is not started while another page is still open (_pageStartState already true). XPS document structure forbids nested pages, so a second RegisterPageStart without an intervening RegisterPageEnd throws XpsSerializationException(SR.ReachSerialization_FixedPageInPage).

Solutions

  1. Call RegisterPageEnd before starting a new page.
  2. Audit the writer loop so each FixedPage start is paired with exactly one end.
  3. Reset/recreate the serialization manager after an exception aborts a page mid-serialization.

Example fix

// before
manager.RegisterPageStart();
manager.RegisterPageStart(); // throws
// after
manager.RegisterPageStart();
// ...serialize page content...
manager.RegisterPageEnd();
manager.RegisterPageStart();
Defensive patterns

Strategy: validation

Validate before calling

// track page state yourself before calling
bool pageOpen = _lastPageStarted && !_lastPageEnded;
if (pageOpen) throw new InvalidOperationException("Previous FixedPage was not ended.");

Try / catch

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

Prevention

When it happens

Trigger: Calling RegisterPageStart twice without calling RegisterPageEnd, i.e. attempting to serialize a FixedPage inside an already-started FixedPage.

Common situations: Custom XPS writers that forget to close the previous page before starting the next; re-entrant serialization triggered by events or recursion; exception paths that skipped RegisterPageEnd leaving state stuck.

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/522b9650dba9cc8e. Report an issue: GitHub.

Appendix: source

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

        OnXPSSerializationProgressChanged(
            object operationState
            )
        {
            XpsSerializationProgressChangedEventArgs e = operationState as XpsSerializationProgressChangedEventArgs;

            if (XpsSerializationProgressChanged != null)
            {
                XpsSerializationProgressChanged(this, e);
            }
        }

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

        internal
        void
        RegisterPageEnd()
        {
            //
            // Exiting Page  Started state
            //

View on GitHub (pinned to 81131a70a4)