{"record":{"id":"83c7ced41f014c61","repo":"microsoft/aspire","slug":"helm-value-key-key-is-invalid-use-letters-digits-or-brackets","errorCode":null,"errorMessage":"Helm value key '{key}' is invalid. Use letters, digits, '.', '-', '_', or brackets for indexed paths.","messagePattern":"Helm value key '(.+?)' is invalid\\. Use letters, digits, '\\.', '-', '_', or brackets for indexed paths\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs","lineNumber":537,"sourceCode":"    // and brackets (for indexed/array paths like \"args[0]\").\n    [GeneratedRegex(@\"^[A-Za-z0-9_.\\-\\[\\]]+$\")]\n    private static partial Regex HelmSetKeyPattern();\n\n    private static void ValidateChartReference(string chartReference, string paramName)\n    {\n        if (!ChartReferencePattern().IsMatch(chartReference))\n        {\n            throw new ArgumentException(\n                $\"Helm chart reference '{chartReference}' is invalid. Use OCI/HTTP URLs, repo/chart names, or local paths containing only letters, digits, '.', '-', '_', '/', ':', '@', '+', '~'.\",\n                paramName);\n        }\n    }\n\n    private static void ValidateHelmSetKey(string key, string paramName)\n    {\n        if (!HelmSetKeyPattern().IsMatch(key))\n        {\n            throw new ArgumentException(\n                $\"Helm value key '{key}' is invalid. Use letters, digits, '.', '-', '_', or brackets for indexed paths.\",\n                paramName);\n        }\n    }\n\n    private static void ValidateHelmSetValue(string value, string paramName)\n    {\n        // Reject control characters (newlines, tabs) and double-quotes that would break the\n        // surrounding quoted argument we hand to the OS process. Helm itself supports richer\n        // value syntax via --set-file / --set-string, which users can wire up later if needed.\n        foreach (var c in value)\n        {\n            if (c == '\"' || c == '\\\\' || char.IsControl(c))\n            {\n                throw new ArgumentException(\n                    $\"Helm value contains an unsupported character (0x{(int)c:X2}). Avoid quotes, backslashes, and control characters; use --values files for complex values.\",\n                    paramName);\n            }","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs#L519-L555","documentation":"Aspire validates every key passed to WithHelmValue against a HelmSetKeyPattern that allows letters, digits, '.', '-', '_' plus bracket notation for indexed array paths (e.g. ingress.hosts[0].host). This mirrors Helm --set key semantics. Keys with other characters (spaces, '=', quotes, unbalanced brackets) are rejected because they would produce invalid or ambiguous Helm --set arguments.","triggerScenarios":"Calling WithHelmValue with a key such as 'service port', 'a=b', 'ingress.hosts[0', 'hosts[]', or any string containing characters outside the allowed pattern.","commonSituations":"Misremembering Helm --set syntax (using '=' inside the key instead of as the separator in raw Helm CLI usage); typos in indexed paths like missing the index number in brackets; accidentally pasting a full 'key=value' pair into the key argument.","solutions":["Use only letters, digits, '.', '-', '_' and balanced bracket indexes (e.g. hosts[0]) in the key.","If you pasted a 'key=value' pair, split it: pass only the key part as the key argument and the value part as the value argument.","For keys with unusual names that cannot fit the pattern, use a values file supplied to the chart instead of WithHelmValue.","Check bracket syntax: every '[' must be matched by ']' and contain a valid index."],"exampleFix":"// before\n.WithHelmValue(\"ingress.hosts[0.host\", \"example.com\");\n// after\n.WithHelmValue(\"ingress.hosts[0].host\", \"example.com\");","handlingStrategy":"validation","validationCode":"var allowed = new System.Text.RegularExpressions.Regex(\"^[a-zA-Z0-9._-]+(\\[[0-9]+\\])?([a-zA-Z0-9._-]*(\\[[0-9]+\\])?)*$\");\n// simpler guard: restrict to pattern-safe chars and balanced [n] segments\nif (!System.Text.RegularExpressions.Regex.IsMatch(key, \"^[a-zA-Z0-9._-]+(\\[[0-9]+\\])?([a-zA-Z0-9._-]+(\\[[0-9]+\\])?)*$\"))\n    throw new ArgumentException($\"Invalid Helm set key: {key}\");","typeGuard":null,"tryCatchPattern":"try { resource.WithHelmValue(key, value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Helm value key\"))\n{ logger.LogError(ex, \"Invalid Helm set key '{Key}'\", key); }","preventionTips":["Model keys as dotted paths with bracket indexes only, e.g. a.b[0].c.","Never paste 'key=value' pairs into the key argument.","Use values files for keys that don't fit the allowed character set."],"tags":["kubernetes","helm","validation","argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}