{"record":{"id":"54fab95fcb1061e2","repo":"dotnet/wpf","slug":"package-must-contain-an-xps-packagepart","errorCode":null,"errorMessage":"Package must contain an XPS PackagePart.","messagePattern":"Package must contain an XPS PackagePart\\.","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs","lineNumber":975,"sourceCode":"                            {\n                                Uri relativeUri = new Uri(attribute, UriKind.Relative);\n                                AddPageToCache(PackUriHelper.ResolvePartUri(Uri, relativeUri));\n                            }\n                        }\n                    }\n                }\n            }\n        }\n\n        private\n        IXpsFixedPageReader\n        AddPageToCache( Uri pageUri )\n        {\n            PackagePart pagePart = CurrentXpsManager.GetPart(pageUri);\n\n            if (pagePart == null)\n            {\n                 throw new XpsPackagingException(SR.ReachPackaging_PartNotFound);\n            }\n\n            if (!pagePart.ValidatedContentType().AreTypeAndSubTypeEqual(XpsS0Markup.FixedPageContentType))\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_NotAFixedPage);\n            }\n\n            //\n            // Create the reader/writer for the part\n            //\n            IXpsFixedPageReader pageReader = new XpsFixedPageReaderWriter(CurrentXpsManager, this, pagePart, null, _pageCache.Count+1);\n\n            //\n            // Cache the new reader/writer for later\n            //\n            _pageCache.Add(pageReader );\n\n            return pageReader;","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs#L957-L993","documentation":"XpsFixedDocumentReaderWriter.AddPageToCache throws XpsPackagingException (ReachPackaging_PartNotFound) when GetPart returns no PackagePart for the given page URI, i.e. the package must contain an XPS PackagePart at that URI but none exists. This occurs while parsing an existing FixedDocument's page relationships into the page cache.","triggerScenarios":"Opening an XPS package whose FixedDocument part has a /FixedPage relationship pointing to a URI with no corresponding part — a broken or hand-edited package.","commonSituations":"Corrupted or truncated .xps files; packages modified by third-party tools that dropped pages but left relationships; manually built OPC packages with mismatched URIs; part-name casing mismatches.","solutions":["Fix or regenerate the source .xps file so every FixedDocument relationship targets an existing FixedPage part.","Validate the package by re-saving it through the OPC/XPS API before opening.","If the page is optional, remove the dangling relationship from the FixedDocument part before reading.","Check part-name casing and relative-vs-absolute URI resolution in the relationship target."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before opening: verify relationship targets resolve\nforeach (var rel in docPart.GetRelationshipsByType(XpsS0Markup.FixedPageRelationshipName))\n    if (docPart.GetPart(rel.TargetUri) == null) throw new Exception(\"Missing part: \" + rel.TargetUri);","typeGuard":null,"tryCatchPattern":"try { ParsePages(); }\ncatch (XpsPackagingException ex) when (ex.Message.Contains(\"PackagePart\")) { /* log broken URI; repair or reject the document */ }","preventionTips":["Validate XPS packages at ingestion time.","Do not hand-edit OPC part URIs.","Regenerate damaged files rather than patching them."],"tags":["wpf","xps","part-not-found","corrupt-package"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}