{"record":{"id":"f4eac774c250a65d","repo":"dotnet/wpf","slug":"sr-notavalidrelationshipparturi","errorCode":null,"errorMessage":"SR.NotAValidRelationshipPartUri","messagePattern":"SR\\.NotAValidRelationshipPartUri","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs","lineNumber":511,"sourceCode":"\n                // must be at least two segments and the last one must end with .RELs\n                // and the length of the segment should be greater than just the extension.\n                if ((segments.Length >= 3) &&\n                    (segments[segments.Length - 1].Length > _relationshipPartExtensionName.Length))\n                {\n                    // look for \"_RELS\" segment which must be second last segment\n                    result = string.Equals(segments[segments.Length - 2], _relationshipPartUpperCaseSegmentName, StringComparison.Ordinal);\n                }\n\n                // In addition we need to make sure that the relationship is not created by taking another relationship\n                // as the source of this uri. So XXX/_rels/_rels/YYY.rels.rels would be invalid.\n                if (segments.Length > 3 && result)\n                {\n                    if ((segments[segments.Length - 1]).EndsWith(_relsrelsUpperCaseExtension, StringComparison.Ordinal))\n                    {\n                        // look for \"_rels\" segment in the third last segment\n                        if(string.Equals(segments[segments.Length - 3], _relationshipPartUpperCaseSegmentName, StringComparison.Ordinal))\n                            throw new ArgumentException(SR.NotAValidRelationshipPartUri);\n                    }\n                }\n\n                return result;\n            }\n\n            //Returns the normalized string for the part uri.            \n            //Currently normalizing the PartUriString consists of only one step - \n            //1. Take the wellformed and escaped partUri string and case fold to UpperInvariant            \n            private string GetNormalizedPartUriString()\n            {\n                //Case Fold the partUri string to Invariant Upper case (this helps us perform case insensitive comparison)\n                //We follow the Simple case folding specified in the Unicode standard\n\n                if (_isNormalized)\n                    return _partUriString;\n                else\n                    return _partUriString.ToUpperInvariant();","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/PackUriHelper.cs#L493-L529","documentation":"ArgumentException with message SR.NotAValidRelationshipPartUri thrown by PackUriHelper.IsRelationshipUri. A pack URI whose part name ends in '.rels' and also contains an upper-case '_rels' segment as the third-last segment is not a valid relationship part name, because '_rels' segments may only appear immediately before the '/xxx.rels' leaf.","triggerScenarios":"Calling PackUriHelper.ValidatedPartUri (or CreatePartUri/GetRelationshipPartUri) with a pack URI like '/a/_rels/b/_rels/c.rels' — i.e., a .rels part nested under another _rels folder, or upper-case _rels segments misplaced in the path.","commonSituations":"Constructing part URIs by string concatenation instead of PackUriHelper APIs; OPC packages produced by non-.NET tools with malformed '_rels' placement; migrating packages between formats that lowercase/uppercase segment names.","solutions":["Build part URIs with PackUriHelper.CreatePartUri instead of manual strings.","Fix the URI so '_rels' appears only as the segment immediately preceding the '.rels' leaf.","Validate the URI with PackUriHelper.IsRelationshipPartUri / ValidatedPartUri before use.","Repair or regenerate the offending package with the Open XML SDK or a known-good producer."],"exampleFix":"// before\nvar uri = new Uri(\"/word/_rels/document/_rels/document.xml.rels\", UriKind.Relative);\n// after\nvar partUri = PackUriHelper.CreatePartUri(new Uri(\"/word/document.xml\", UriKind.Relative));\nvar relsUri = PackUriHelper.GetRelationshipPartUri(partUri); // /word/_rels/document.xml.rels","handlingStrategy":"validation","validationCode":"bool IsValidRelsUri(Uri u) => !u.ToString().Contains(\"_rels/\") || PackUriHelper.IsRelationshipPartUri(u);","typeGuard":null,"tryCatchPattern":"try { partUri = PackUriHelper.ValidatedPartUri(uri); }\ncatch (ArgumentException) { /* log malformed pack URI, reject package */ }","preventionTips":["Use PackUriHelper.CreatePartUri for all part URIs","Never hand-concatenate '_rels' segments","Sanitize third-party package part names on import"],"tags":["pack-uri","argumentexception","opc","validation"],"backgroundTag":"invalid-argument-format","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"}