{"record":{"id":"3681a58d40391458","repo":"dotnet/maui","slug":"indexer-did-not-contain-arguments","errorCode":null,"errorMessage":"Indexer did not contain arguments","messagePattern":"Indexer did not contain arguments","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindingExpression.cs","lineNumber":248,"sourceCode":"\t\t\tstring[] pathParts = p.Split(ExpressionSplit);\n\t\t\tfor (var i = 0; i < pathParts.Length; i++)\n\t\t\t{\n\t\t\t\tstring part = pathParts[i].Trim();\n\t\t\t\tif (part == string.Empty)\n\t\t\t\t\tthrow new FormatException(\"Path contains an empty part\");\n\n\t\t\t\tBindingExpressionPart indexer = null;\n\n\t\t\t\tint lbIndex = part.IndexOf(\"[\", StringComparison.Ordinal);\n\t\t\t\tif (lbIndex != -1)\n\t\t\t\t{\n\t\t\t\t\tint rbIndex = part.Length - 1;\n\t\t\t\t\tif (part[rbIndex] != ']')\n\t\t\t\t\t\tthrow new FormatException(\"Indexer did not contain closing bracket\");\n\n\t\t\t\t\tint argLength = rbIndex - lbIndex - 1;\n\t\t\t\t\tif (argLength == 0)\n\t\t\t\t\t\tthrow new FormatException(\"Indexer did not contain arguments\");\n\n\t\t\t\t\tstring argString = part.Substring(lbIndex + 1, argLength);\n\t\t\t\t\tindexer = new BindingExpressionPart(this, argString, true);\n\n\t\t\t\t\tpart = part.Substring(0, lbIndex);\n\t\t\t\t\tpart = part.Trim();\n\t\t\t\t}\n\t\t\t\tif (part.Length > 0)\n\t\t\t\t{\n\t\t\t\t\tvar next = new BindingExpressionPart(this, part);\n\t\t\t\t\tlast.NextPart = next;\n\t\t\t\t\t_parts.Add(next);\n\t\t\t\t\tlast = next;\n\t\t\t\t}\n\t\t\t\tif (indexer != null)\n\t\t\t\t{\n\t\t\t\t\tlast.NextPart = indexer;\n\t\t\t\t\t_parts.Add(indexer);","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindingExpression.cs#L230-L266","documentation":"Thrown while parsing an indexer segment when the brackets contain no argument (argLength == 0), i.e. an empty indexer like '[]'. The indexer requires at least one character between '[' and ']' to identify the key/ index.","triggerScenarios":"Paths like \"Items[]\", \"Dict[]\". Building a path with an empty index variable: $\"Items[{index}]\" where index is empty.","commonSituations":"Index variable is null or empty string due to uninitialized state. Conditional path building that omits the index value. Deserialization producing empty indexer keys.","solutions":["Ensure the index/key value is non-empty before building the path.","Validate the path with a regex that rejects empty indexer brackets (brackets containing no argument).","Fall back to a safe default index or skip the indexer when the value is missing."],"exampleFix":"// before\nvar path = $\"Items[{index}]\"; // index == \"\"\n\n// after\nif (string.IsNullOrEmpty(index))\n    throw new ArgumentException(\"Index must be non-empty\", nameof(index));\nvar path = $\"Items[{index}]\";","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(index))\n    throw new ArgumentException(\"Indexer key must be non-empty\", nameof(index));\nvar path = $\"Items[{index}]\";","typeGuard":"static bool IsValidIndexer(string path) =>\n    !Regex.IsMatch(path, @\"\\[\\s*\\]\"); // reject empty []","tryCatchPattern":null,"preventionTips":["Ensure index/key variables are non-empty before building the path.","Reject '[]' in path validation.","Default missing indices to a sentinel like 0 instead of empty."],"tags":["maui","binding","path","indexer","validation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}