{"record":{"id":"831918e369255a44","repo":"microsoft/aspire","slug":"helm-value-contains-an-unsupported-character-0x-c-x2-avoid","errorCode":null,"errorMessage":"Helm value contains an unsupported character (0x{c:X2}). Avoid quotes, backslashes, and control characters; use --values files for complex values.","messagePattern":"Helm value contains an unsupported character \\(0x(.+?)\\)\\. Avoid quotes, backslashes, and control characters; use --values files for complex values\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs","lineNumber":552,"sourceCode":"    {\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            }\n        }\n    }\n\n    // Wraps an already-validated argument fragment in double quotes for safe interpolation\n    // into the helm arguments string. Callers must validate that the value contains no\n    // embedded quotes, backslashes, or control characters first.\n    private static string QuoteArg(string value) => $\"\\\"{value}\\\"\";\n}\n","sourceCodeStart":534,"sourceCodeEnd":564,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs#L534-L564","documentation":"Aspire validates Helm values passed to WithHelmValue to ensure the resulting Helm --set command-line argument is safe. Values containing double quotes, backslashes, or any control character are rejected because they would break quoting/escaping of the OS process argument. Complex values needing quotes should be provided via a values file (--values / --set-file), as the comment in the source notes.","triggerScenarios":"Calling WithHelmValue with a value containing a double quote, a backslash (e.g. a Windows path or regex), or a control character such as a newline, tab, or carriage return embedded in the string.","commonSituations":"Passing multi-line YAML/JSON or a formatted string as a single --set value; passing Windows file paths with backslashes; strings read from files or user input that include trailing newlines or tabs; attempting to embed quoted shell fragments in the value.","solutions":["Remove or replace quotes, backslashes, and control characters (trim whitespace/newlines from values read from files).","Use forward slashes for paths inside the value.","For complex values (JSON, YAML, multi-line, quoted), write them to a values file and supply it through the chart's values-file API instead of WithHelmValue.","Use Helm's --set-string / --set-file semantics via the appropriate Aspire API if the value must be treated literally."],"exampleFix":"// before\n.WithHelmValue(\"config\", \"{\\\"a\\\": 1}\\n\");\n// after\n.WithHelmValue(\"config\", \"{a: 1}\"); // or supply a values file for complex payloads","handlingStrategy":"validation","validationCode":"if (value.Any(c => c == '\"' || c == '\\\\' || char.IsControl(c)))\n    throw new ArgumentException(\"Helm value contains quotes, backslashes, or control characters\");","typeGuard":null,"tryCatchPattern":"try { resource.WithHelmValue(key, value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"unsupported character\"))\n{ logger.LogError(ex, \"Value for '{Key}' contains quotes/backslashes/control chars; use a values file\", key); }","preventionTips":["Trim values read from files or environment variables to remove trailing newlines/tabs.","Use forward slashes for any path-like values.","Move complex or quoted values into a values file instead of WithHelmValue."],"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"}