dotnet/wpf · error · XpsPackagingException
FixedDocument has more than one related document structure.
Error message
FixedDocument has more than one related document structure.
What it means
XpsFixedDocumentReaderWriter.AddDocumentStructure throws XpsPackagingException (ReachPackaging_MoreThanOneDocStructure) when the FixedDocument already has a document structure part. The XPS spec permits at most one DocumentStructure relationship per FixedDocument. This is an eager check via the DocumentStructure property before creating a new structure part.
Solutions
- Check the DocumentStructure property before calling AddDocumentStructure and skip if already non-null.
- Track in application state whether the structure part was created for this document.
- Rebuild the package if you truly need a new document structure; you cannot add a second one.
Example fix
// before
doc.AddDocumentStructure();
doc.AddDocumentStructure(); // throws
// after
if (doc.DocumentStructure == null)
doc.AddDocumentStructure(); Defensive patterns
Strategy: validation
Validate before calling
if (doc.DocumentStructure == null)
doc.AddDocumentStructure(); Try / catch
try { doc.AddDocumentStructure(); }
catch (XpsPackagingException) { /* structure already exists; reuse it */ } Prevention
- Guard every AddDocumentStructure call with a null check on DocumentStructure.
- Make structure creation idempotent in helper methods.
- Avoid retry wrappers that can re-run the creation step.
When it happens
Trigger: Calling AddDocumentStructure a second time on the same XpsFixedDocumentReaderWriter after a document structure part was already added (DocumentStructure property is non-null).
Common situations: Retry logic that re-invokes AddDocumentStructure after a partial failure; refactors that call it both in setup and in a write loop; accidental duplicate processing of the same document.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Container already has Starting Part.
- FixedPage has more than one related story fragment.
- SR.ReachPackaging_ServiceTypeAlreadyAdded
- SR.ReachSerialization_FixedDocumentInDocument
- SR.ReachSerialization_FixedDocumentInPage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f02951b8771b8661.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs:475
_thumbnail = CurrentXpsManager.AddThumbnail( imageType, this, Thumbnail );
_metroPart.CreateRelationship( _thumbnail.Uri,
TargetMode.Internal,
XpsS0Markup.ThumbnailRelationshipName
);
return _thumbnail;
}
/// <summary>
/// </summary>
public
XpsStructure
AddDocumentStructure(
)
{
if (this.DocumentStructure != null)
{
// Document structure already available for this FixedDocument
throw new XpsPackagingException(SR.ReachPackaging_MoreThanOneDocStructure);
}
Uri pageUri = this.CurrentXpsManager.CreateStructureUri();
//
// Create the part and writer
//
PackagePart metroPart = this.CurrentXpsManager.GeneratePart(
XpsS0Markup.DocumentStructureContentType,
pageUri);
_documentStructure = new XpsStructure(CurrentXpsManager, this, metroPart);
//
// Create the relationship between the document and the document-structure
// Not in INode.Flush because IXpsFixedDocumentReader has no commit.
//
string structurePath = XpsManager.MakeRelativePath(this.Uri, _documentStructure.Uri);View on GitHub (pinned to 81131a70a4)