{"record":{"id":"ea0e3693bd3a1638","repo":"dotnet/wpf","slug":"document-packagepart-uri-is-not-valid","errorCode":null,"errorMessage":"Document PackagePart URI is not valid.","messagePattern":"Document PackagePart URI is not valid\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs","lineNumber":579,"sourceCode":"                documentPart.CreateRelationship(\n                    sigDefPart.Uri,\n                    TargetMode.Internal,\n                    XpsS0Markup.SignatureDefinitionRelationshipName\n                    );\n            }\n            return sigDefPart;\n        }\n\n        public\n        PackagePart\n        GetSignatureDefinitionPart(Uri documentUri)\n        {\n            PackagePart documentPart = _metroPackage.GetPart( documentUri );\n            PackagePart sigDefPart = null;\n\n            if( documentPart == null )\n            {\n              throw new InvalidDataException(SR.ReachPackaging_InvalidDocUri);\n            }\n\n            ContentType SignitureDefType =\n                XpsS0Markup.SignatureDefintionType;\n            PackageRelationship SigDefRel = null;\n\n            foreach (PackageRelationship rel in\n                     documentPart.GetRelationshipsByType(XpsS0Markup.SignatureDefinitionRelationshipName))\n            {\n                if (SigDefRel != null)\n                {\n                    throw new InvalidDataException(SR.ReachPackaging_MoreThanOneSigDefParts);\n                }\n\n                SigDefRel = rel;\n            }\n            if (SigDefRel != null)\n            {","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs#L561-L597","documentation":"GetSignatureDefinitionPart looks up the document part by its URI via _metroPackage.GetPart(documentUri) and throws InvalidDataException (SR.ReachPackaging_InvalidDocUri) when GetPart returns null, meaning the package contains no part at that URI. This indicates the documentUri supplied does not address an existing part in the package.","triggerScenarios":"Calling GetSignatureDefinitionPart with a documentUri that does not resolve to a part in the opened XPS package — wrong part path, typo in URI, or the document part was never added/removed.","commonSituations":"Hard-coded part URIs (e.g. \"/Documents/1/Pages/1.fpage\") that don't match the actual package layout; packages edited or regenerated with different document numbering; case-sensitivity or missing leading slash in the URI.","solutions":["Obtain documentUri from the package itself (e.g. via GetParts / fixed document sequence) instead of hard-coding it.","Verify the URI exists with _metroPackage.PartExists(documentUri) before calling.","Fix the URI format: use a valid pack part URI with correct casing and leading '/'.","Re-open the correct package — the URI may belong to a different document than the one loaded."],"exampleFix":"// before\nvar sigPart = xpsManager.GetSignatureDefinitionPart(new Uri(\"/Documents/1/Pages/1.fpage\", UriKind.Relative));\n// after\nvar docUri = new Uri(\"/Documents/1/Pages/1.fpage\", UriKind.Relative);\nif (!package.PartExists(docUri)) throw new FileNotFoundException($\"Document part {docUri} not found in package\");\nvar sigPart = xpsManager.GetSignatureDefinitionPart(docUri);","handlingStrategy":"validation","validationCode":"var docUri = new Uri(path, UriKind.Relative);\nif (!_metroPackage.PartExists(docUri)) throw new ArgumentException($\"Document part '{path}' does not exist in the package\");","typeGuard":"bool DocumentExists(Package pkg, Uri uri) => pkg?.PartExists(uri) == true;","tryCatchPattern":"try { return xpsManager.GetSignatureDefinitionPart(docUri); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"URI\")) { /* enumerate package parts to find the correct document URI */ return null; }","preventionTips":["Derive document URIs from the package's own part list, not hard-coded strings.","Normalize part URIs with PackUriHelper where possible.","Log available part URIs when a lookup fails to speed diagnosis."],"tags":["wpf","xps","uri","packaging"],"backgroundTag":"entity-not-found","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"}