{"record":{"id":"9cf2ca08d1d08b12","repo":"dotnet/wpf","slug":"sr-format-sr-pathparametersindexoutofrange-index","errorCode":null,"errorMessage":"SR.Format(SR.PathParametersIndexOutOfRange, index, PathParameters.Count)","messagePattern":"SR\\.Format\\(SR\\.PathParametersIndexOutOfRange, index, PathParameters\\.Count\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs","lineNumber":560,"sourceCode":"            string propertyName = name;\n            int index;\n\n            // first see if the name is an index into the parameter list\n            if (IsParameterIndex(name, out index))\n            {\n                if (0 <= index && index < PathParameters.Count)\n                {\n                    object accessor = PathParameters[index];\n                    // always throw if the accessor isn't valid - this error cannot\n                    // be corrected later on.\n                    if (!IsValidAccessor(accessor))\n                        throw new InvalidOperationException(SR.Format(SR.PropertyPathInvalidAccessor,\n                                    (accessor != null) ? accessor.GetType().FullName : \"null\"));\n\n                    return accessor;\n                }\n                else if (throwOnError)\n                    throw new InvalidOperationException(SR.Format(SR.PathParametersIndexOutOfRange, index, PathParameters.Count));\n                else return null;\n            }\n\n            // handle attached-property syntax:  (TypeName.PropertyName)\n            if (IsPropertyReference(name))\n            {\n                name = name.Substring(1, name.Length-2);\n\n                int lastIndex = name.LastIndexOf('.');\n                if (lastIndex >= 0)\n                {\n                    // attached property - get the owner type\n                    propertyName = name.Substring(lastIndex + 1).Trim();\n                    string ownerName = name.Substring(0, lastIndex).Trim();\n                    ownerType = GetTypeFromName(ownerName, context);\n                    if (ownerType == null && throwOnError)\n                        throw new InvalidOperationException(SR.Format(SR.PropertyPathNoOwnerType, ownerName));\n                }","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs#L542-L578","documentation":"ResolvePropertyName throws this InvalidOperationException when the path string references a parameter index that does not exist in PathParameters. Property names written as '(n)' index into the PathParameters collection; if index < 0 or index >= PathParameters.Count and throwOnError is true, resolution cannot proceed and the path is invalid.","triggerScenarios":"A path string like '(5).Text' when PathParameters.Count is 3; calling new PropertyPath(pathString) with '(n)' references but never adding the corresponding accessors; negative indices from malformed path syntax.","commonSituations":"Copy-pasting property path strings between bindings without updating the PathParameters collection; generating paths dynamically where the accessor count depends on runtime data; typos in the numeric index inside parentheses.","solutions":["Add one accessor to PathParameters for every '(n)' reference in the path string, in order","Fix the numeric index inside the path string so it is within [0, PathParameters.Count)","Replace the '(n)' indexed syntax with literal property names if accessors are not needed","Validate the path string and PathParameters.Count before constructing/using the PropertyPath"],"exampleFix":"// before\nvar path = new PropertyPath(\"(2).Value\"); // only 2 accessors added\npath.PathParameters.Add(typeof(A).GetProperty(\"X\"));\npath.PathParameters.Add(typeof(B).GetProperty(\"Y\"));\n// after\nvar path = new PropertyPath(\"(1).Value\");\npath.PathParameters.Add(typeof(A).GetProperty(\"X\"));\npath.PathParameters.Add(typeof(B).GetProperty(\"Y\"));","handlingStrategy":"validation","validationCode":"// pathString is the raw path; count '(n)' references and compare\nint maxIdx = System.Text.RegularExpressions.Regex.Matches(pathString, \"\\\\((\\\\d+)\\\\)\")\n    .Select(m => int.Parse(m.Groups[1].Value)).DefaultIfEmpty(-1).Max();\nbool inRange = maxIdx < path.PathParameters.Count;","typeGuard":"bool IndexInRange(int i, System.Collections.ICollection c) => i >= 0 && i < c.Count;","tryCatchPattern":"try { path.ResolvePropertyName(index, item, context, throwOnError: true); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"out of range\")) { /* fix index or add parameter */ }","preventionTips":["Keep a 1:1 correspondence between '(n)' references in the path string and PathParameters entries","Log/assert PathParameters.Count when constructing indexed paths","Use literal property names when accessors are unnecessary"],"tags":["wpf","binding","property-path","index-out-of-range"],"backgroundTag":"index-out-of-range","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"}