dotnet/wpf · error · XpsSerializationException
SR.ReachSerialization_FixedDocumentInDocument
Error message
SR.ReachSerialization_FixedDocumentInDocument
What it means
RegisterDocumentStart rejects starting a FixedDocument while another document is still open (_documentStartState true). XPS forbids nested FixedDocuments, so a second RegisterDocumentStart without RegisterDocumentEnd throws XpsSerializationException(SR.ReachSerialization_FixedDocumentInDocument).
Solutions
- Call RegisterDocumentEnd before starting the next document.
- Pair every RegisterDocumentStart with exactly one RegisterDocumentEnd in the writer loop.
- Reinitialize the serialization manager if a previous error left the document state machine inconsistent.
Example fix
// before manager.RegisterDocumentStart(); manager.RegisterDocumentStart(); // throws // after manager.RegisterDocumentStart(); // ...serialize document... manager.RegisterDocumentEnd(); manager.RegisterDocumentStart();
Defensive patterns
Strategy: validation
Validate before calling
bool docOpen = _docStarted && !_docEnded;
if (docOpen) throw new InvalidOperationException("Previous FixedDocument was not ended."); Try / catch
try { manager.RegisterDocumentStart(); }
catch (XpsSerializationException ex) when (ex.Message.Contains("FixedDocumentInDocument")) { manager.RegisterDocumentEnd(); manager.RegisterDocumentStart(); } Prevention
- Pair RegisterDocumentStart with exactly one RegisterDocumentEnd
- Follow the canonical Register* call order
- Recreate the manager after aborted serializations
When it happens
Trigger: Calling RegisterDocumentStart twice without an intervening RegisterDocumentEnd, i.e. nesting a FixedDocument inside an open FixedDocument.
Common situations: Custom writers that miss the end-of-document call between documents; re-entrant or event-driven serialization; recovery paths that left _documentStartState set after an exception.
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_FixedDocumentInPage
- SR.ReachSerialization_FixedPageInPage
- SR.ReachSerialization_FixedDocumentInDocument
- SR.ReachSerialization_FixedDocumentInPage
- SR.ReachSerialization_FixedPageInPage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/754f650281b7e04e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs:700
RegisterDocumentSequenceEnd()
{
//
// It is invalid to have a document sequence with no fixed documents
// 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;
}View on GitHub (pinned to 81131a70a4)