{"record":{"id":"a4b9ad6ed55de810","repo":"dotnet/wpf","slug":"sr-format-sr-propertypathindexwrongtype-paramlist-i","errorCode":null,"errorMessage":"SR.Format(SR.PropertyPathIndexWrongType, paramList[i].parenString, paramList[i].valueString)","messagePattern":"SR\\.Format\\(SR\\.PropertyPathIndexWrongType, paramList\\[i\\]\\.parenString, paramList\\[i\\]\\.valueString\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs","lineNumber":754,"sourceCode":"                        // treated it like this, so to preserve compatibility...]\n                        args[i].value = $\"({paramList[i].parenString})\";\n                    }\n                }\n                else\n                {\n                    // both strings appear \"(Double)3.14159\" - value is type-converted from value string\n                    args[i].type = GetTypeFromName(paramList[i].parenString, context);\n                    if (args[i].type != null)\n                    {\n                        object value = GetTypedParamValue(paramList[i].valueString.Trim(), args[i].type, throwOnError);\n                        if (value != null)\n                        {\n                            args[i].value = value;\n                        }\n                        else\n                        {\n                            if (throwOnError)\n                                throw new InvalidOperationException(SR.Format(SR.PropertyPathIndexWrongType, paramList[i].parenString, paramList[i].valueString));\n                            args[i].type = null;\n                        }\n                    }\n                    else\n                    {\n                        // parens didn't hold a type name \"(abc)xyz\" - value is (uninterpreted) string\n                        // [this could be considered an error, but the original code\n                        // treated it like this, so to preserve compatibility...]\n                        args[i].value = $\"({paramList[i].parenString}){paramList[i].valueString}\";\n                    }\n                }\n            }\n            return args;\n        }\n\n        private object GetTypedParamValue(string param, Type type, bool throwOnError)\n        {\n            object value = null;","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs#L736-L772","documentation":"ResolveIndexerParams throws this InvalidOperationException when an indexer parameter written as '(TypeName)valueString' cannot have valueString converted to TypeName. The type name resolved successfully, but the value string is not convertible to that type (e.g. a non-numeric string for Int32), so the indexer argument has the wrong type.","triggerScenarios":"Path like '(Int32)abc' where 'abc' is not parseable as an integer; type-qualified indexer parameters such as '[(Int32)xyz]' where the value string was meant for a string-typed indexer; culture/format mismatches in numeric strings.","commonSituations":"XAML binding indexer paths with typed parameters, e.g. Binding Path='[(sys:Int32)not-a-number]'; localizations altering numeric formatting (comma vs dot decimals); typos in the value string after copying a working path.","solutions":["Correct the value string so it is convertible to the named type (e.g. '(Int32)42')","Remove the '(TypeName)' prefix if the value should remain an uninterpreted string","Pre-validate conversion with Convert.ChangeType or TypeConverter.CanConvertFrom before constructing the path","Use the correct target type name matching the indexer's parameter type"],"exampleFix":"// before\nvar path = new PropertyPath(\"[(Int32)twelve]\");\n// after\nvar path = new PropertyPath(\"[(Int32)12]\");","handlingStrategy":"validation","validationCode":"bool convertible = int.TryParse(valueString, out _); // for (Int32) parameters\n// general: System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(int));\n// tc.CanConvertFrom(typeof(string)) && tc.IsValid(valueString)","typeGuard":"bool CanParse<T>(string s) where T : IConvertible =>\n    System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)).IsValid(s);","tryCatchPattern":"try { path.ResolveIndexerParams(list, item, context, throwOnError: true); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"wrong type\") || ex.Message.Contains(\"convert\")) { /* fix the value string */ }","preventionTips":["Match the value string's format to the target type (culture-aware parsing for decimals)","Use invariant culture numeric strings in XAML path values","Validate typed indexer values with TypeConverter.IsValid before constructing paths"],"tags":["wpf","binding","property-path","indexer","type-mismatch"],"backgroundTag":"type-mismatch","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"}