dotnet/wpf · error · XpsSerializationException
SR.ReachSerialization_FixedDocumentInPage
Error message
SR.ReachSerialization_FixedDocumentInPage
What it means
RegisterDocumentStart also rejects starting a document while a page is still open (_pageStartState). If a FixedPage has been started but not ended, starting a FixedDocument would illegally nest a document inside a page, so XpsSerializationException(SR.ReachSerialization_FixedDocumentInPage) is thrown.
Solutions
- Ensure RegisterPageEnd (and page commit) is always called before RegisterDocumentStart, including on error paths (try/finally).
- Restructure pagination so documents and pages nest correctly: DocumentSequence > Document > Page.
- Add assertions/logging around the register calls to catch ordering bugs early.
- Use DocumentPaginator + XpsDocumentWriter to let WPF manage document/page sequencing.
Example fix
// before manager.RegisterPageStart(); manager.RegisterDocumentStart(); // document inside open page // after manager.RegisterPageStart(); manager.RegisterPageEnd(); manager.RegisterDocumentEnd(); manager.RegisterDocumentStart();
Defensive patterns
Strategy: validation
Validate before calling
if (pageOpen)
throw new InvalidOperationException("Cannot start a FixedDocument while a FixedPage is open; call RegisterPageEnd first."); Try / catch
try
{
manager.RegisterDocumentStart();
}
catch (System.Windows.Xps.XpsSerializationException ex) when (ex.Message.Contains("page"))
{
// close the dangling page/document chain before retrying
manager.RegisterPageEnd();
manager.RegisterDocumentEnd();
manager.RegisterDocumentStart();
} Prevention
- Wrap page serialization in try/finally so RegisterPageEnd always runs, even on exceptions.
- Nest calls in the correct order: sequence start > document start > page start/end > document end > sequence end.
- Log each register call in debug builds to catch ordering violations early.
When it happens
Trigger: Calling RegisterDocumentStart after RegisterPageStart without RegisterPageEnd — e.g. a paginator that begins a new document mid-page, or missing/failed page-end cleanup on an exception path.
Common situations: Error-handling gaps where RegisterPageEnd is skipped after a serialization failure; per-page document rotation logic in custom XPS writers; async serialization callbacks firing out of order.
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
- SR.ReachSerialization_FixedDocumentInDocument
- SR.ReachSerialization_FixedDocumentInDocument
- SR.ReachSerialization_FixedDocumentInPage
- SR.ReachSerialization_FixedPageInPage
- SR.ReachSerialization_FixedPageInPage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/037983191b5d29fb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsSerializationManager.cs:844
AddRelationshipToCurrentPage(
Uri targetUri,
string relationshipName
)
{
_packagingPolicy?.RelateResourceToCurrentPage(targetUri, relationshipName);
}
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
voidView on GitHub (pinned to 81131a70a4)