{"record":{"id":"7cbbda21baebab3f","repo":"dotnet/wpf","slug":"packagepart-uri-does-not-correspond-to-a-fixeddocument","errorCode":null,"errorMessage":"PackagePart URI does not correspond to a FixedDocument.","messagePattern":"PackagePart URI does not correspond to a FixedDocument\\.","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentSequenceReaderWriter.cs","lineNumber":619,"sourceCode":"        private\n        IXpsFixedDocumentReader\n        AddDocumentToCache(Uri documentUri)\n        {\n            //\n            // Retrieve the requested part from the package\n            //\n            PackagePart documentPart = CurrentXpsManager.GetPart(documentUri);\n            if (documentPart == null)\n            {\n                 throw new XpsPackagingException(SR.ReachPackaging_PartNotFound);\n            }\n\n            //\n            // If the part is not a fixed document then throw an exception\n            //\n            if (!documentPart.ValidatedContentType().AreTypeAndSubTypeEqual(XpsS0Markup.FixedDocumentContentType))\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_NotAFixedDocument);\n            }\n\n            //\n            // Create the reader/writer for the part\n            //\n            IXpsFixedDocumentReader  fixedDocument = new XpsFixedDocumentReaderWriter(CurrentXpsManager, null, documentPart, _documentCache.Count+1);\n\n            //\n            // Cache the new reader/writer for later\n            //\n            _documentCache.Add( fixedDocument );\n            return fixedDocument;\n        }\n\n\n        #endregion Private methods\n\n        #region Private data","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentSequenceReaderWriter.cs#L601-L637","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// package manually re-zipped: Documents/1/FixedDoc.fdoc content type lost\n// after\n// Repack so [Content_Types].xml contains:\n// <Default Extension=\"fdoc\" ContentType=\"application/vnd.ms-package.xps-fixeddocument\"/>\n// or rebuild via:\nusing (XpsDocument doc = new XpsDocument(outPath, FileAccess.ReadWrite))\n{\n    IXpsFixedDocumentSequenceWriter w = doc.AddFixedDocumentSequence();\n    // ... write documents through the API\n    w.Commit();\n}","handlingStrategy":"validation","validationCode":"// Before reading: confirm the target part's content type is FixedDocument\nUri partUri = PackUriHelper.ResolvePartUri(seqUri, rel.TargetUri);\nPackagePart part = package.GetPart(partUri);\nif (!part.ContentType.Equals(\"application/vnd.ms-package.xps-fixeddocument\", StringComparison.OrdinalIgnoreCase))\n    throw new InvalidDataException($\"Part {partUri} is {part.ContentType}, not a FixedDocument\");","typeGuard":"static bool IsFixedDocumentPart(PackagePart part) =>\n    part != null && string.Equals(part.ContentType,\n        \"application/vnd.ms-package.xps-fixeddocument\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try\n{\n    var reader = seqReader.GetFixedDocumentAt(i);\n}\ncatch (XpsPackagingException ex) when (ex.Message.Contains(\"FixedDocument\"))\n{\n    // skip/flag malformed document entry\n    log.Warn($\"Document {i} has wrong content type: {ex.Message}\");\n}","preventionTips":["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."],"tags":["xps","wpf","packaging","content-type"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}