dotnet/wpf · error · XpsPackagingException
PackagePart URI does not correspond to a FixedDocument.
Error message
PackagePart URI does not correspond to a FixedDocument.
What it means
XpsPackagingException thrown by AddDocumentToCache when the part at the document URI exists in the package but its validated content type is not FixedDocumentContentType. The FixedDocumentSequence referenced a part that is present but is not a FixedDocument. The library throws to prevent building a reader for the wrong part type.
Solutions
- Open the package as a zip and confirm the target part's entry in [Content_Types].xml maps to the FixedDocument content type (application/vnd.ms-package.xps-fixeddocument).
- Regenerate the XPS from the original application rather than manually re-zipping, which can drop correct content-type mappings.
- Verify the FixedDocumentSequence relationship targets the .fdoc/FixedDocument part, not a page or resource.
- If authoring packages, use XpsDocument/XpsFixedDocumentSequenceWriter APIs so content types are set automatically.
- Validate input files with an XPS conformance checker before processing.
Example fix
// before
// package manually re-zipped: Documents/1/FixedDoc.fdoc content type lost
// after
// Repack so [Content_Types].xml contains:
// <Default Extension="fdoc" ContentType="application/vnd.ms-package.xps-fixeddocument"/>
// or rebuild via:
using (XpsDocument doc = new XpsDocument(outPath, FileAccess.ReadWrite))
{
IXpsFixedDocumentSequenceWriter w = doc.AddFixedDocumentSequence();
// ... write documents through the API
w.Commit();
} Defensive patterns
Strategy: validation
Validate before calling
// Before reading: confirm the target part's content type is FixedDocument
Uri partUri = PackUriHelper.ResolvePartUri(seqUri, rel.TargetUri);
PackagePart part = package.GetPart(partUri);
if (!part.ContentType.Equals("application/vnd.ms-package.xps-fixeddocument", StringComparison.OrdinalIgnoreCase))
throw new InvalidDataException($"Part {partUri} is {part.ContentType}, not a FixedDocument"); Type guard
static bool IsFixedDocumentPart(PackagePart part) =>
part != null && string.Equals(part.ContentType,
"application/vnd.ms-package.xps-fixeddocument", StringComparison.OrdinalIgnoreCase); Try / catch
try
{
var reader = seqReader.GetFixedDocumentAt(i);
}
catch (XpsPackagingException ex) when (ex.Message.Contains("FixedDocument"))
{
// skip/flag malformed document entry
log.Warn($"Document {i} has wrong content type: {ex.Message}");
} Prevention
- Keep [Content_Types].xml intact when repacking; verify .fdoc default/override entries exist.
- Don't rename FixedDocument parts; extensions drive inferred content types.
- Always author packages through XpsDocument/XpsFixedDocumentSequenceWriter APIs.
- Validate XPS inputs against the OPC/XPS spec before processing third-party files.
When it happens
Trigger: Calling document-reading APIs on an XPS package where the FixedDocumentSequence's document relationship targets a part whose ContentType is not the FixedDocument MIME type — e.g. the URI points to a FixedPage, a thumbnail, or a renamed custom part.
Common situations: XPS files produced by nonconforming generators that mislabel content types; packages where [Content_Types].xml entries were edited or lost; a FixedDocument part renamed with an extension that changed its inferred type; mixing .oxps/.xps content-type conventions.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- ' ' ContentType is not valid.
- Can only countersign parts with Digital Signature…
- Document PackagePart URI is not valid.
- Only writers can call this method.
- Package must contain an XPS PackagePart.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7cbbda21baebab3f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentSequenceReaderWriter.cs:619
private
IXpsFixedDocumentReader
AddDocumentToCache(Uri documentUri)
{
//
// Retrieve the requested part from the package
//
PackagePart documentPart = CurrentXpsManager.GetPart(documentUri);
if (documentPart == null)
{
throw new XpsPackagingException(SR.ReachPackaging_PartNotFound);
}
//
// If the part is not a fixed document then throw an exception
//
if (!documentPart.ValidatedContentType().AreTypeAndSubTypeEqual(XpsS0Markup.FixedDocumentContentType))
{
throw new XpsPackagingException(SR.ReachPackaging_NotAFixedDocument);
}
//
// Create the reader/writer for the part
//
IXpsFixedDocumentReader fixedDocument = new XpsFixedDocumentReaderWriter(CurrentXpsManager, null, documentPart, _documentCache.Count+1);
//
// Cache the new reader/writer for later
//
_documentCache.Add( fixedDocument );
return fixedDocument;
}
#endregion Private methods
#region Private dataView on GitHub (pinned to 81131a70a4)