dotnet/wpf · error · XpsPackagingException
ReachPackaging_AlreadyHasRootSequenceOrDocument
Error message
ReachPackaging_AlreadyHasRootSequenceOrDocument
What it means
AddFixedDocumentSequence throws this InvalidOperationException when the package already contains a root FixedDocumentSequence (or fixed-document starting part). An XPS package may have only one document sequence root, so adding another is rejected. Check for an existing root sequence before calling.
Solutions
- Call AddFixedDocumentSequence only once per package, before the root FixedDocumentSequence is written
- Use the existing IXpsFixedDocumentSequenceWriter returned from the first call instead of adding another
- Check whether the package already contains a root FixedDocumentSequence before calling
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs:544 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6c8fe9df8f038cde.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs:544
/// is already a starting part causes InvalidOperationException to be
/// thrown.
/// </summary>
/// <returns>Returns a IXpsFixedDocumentSequenceWriter instance.</returns>
/// <exception cref="SR.ReachPackaging_AlreadyHasRootSequenceOrDocument">Package already has a root DocumentSequence.</exception>
public
IXpsFixedDocumentSequenceWriter
AddFixedDocumentSequence(
)
{
CheckDisposed();
if( CurrentXpsManager == null )
{
throw new InvalidOperationException(SR.ReachPackaging_DocumentWasClosed);
}
if (_isInDocumentStage)
{
throw new XpsPackagingException(SR.ReachPackaging_AlreadyHasRootSequenceOrDocument);
}
if ( !CurrentXpsManager.Streaming && null != CurrentXpsManager.StartingPart)
{
throw new XpsPackagingException(SR.ReachPackaging_AlreadyHasRootSequenceOrDocument);
}
//
// Create the unique metro part in the package
//
PackagePart metroPart = CurrentXpsManager.GenerateUniquePart(XpsS0Markup.DocumentSequenceContentType);
//
// Create reader/writer and save a reference to it.
//
XpsFixedDocumentSequenceReaderWriter ds = new XpsFixedDocumentSequenceReaderWriter(CurrentXpsManager, this, metroPart);
CurrentXpsManager.StartingPart = ((INode)ds).GetPart();
View on GitHub (pinned to 81131a70a4)