{"record":{"id":"3a3a4d608ada7941","repo":"microsoft/aspire","slug":"command-line-args-must-be-strings-kubernetesresource","errorCode":null,"errorMessage":"Command line args must be strings","messagePattern":"Command line args must be strings","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesResource.cs","lineNumber":383,"sourceCode":"        if (resource.TryGetAnnotationsOfType<CommandLineArgsCallbackAnnotation>(out var commandLineArgsCallbackAnnotations))\n        {\n            var context = new CommandLineArgsCallbackContext([], resource, cancellationToken: cancellationToken)\n            {\n                ExecutionContext = executionContext\n            };\n\n            foreach (var c in commandLineArgsCallbackAnnotations)\n            {\n                await c.Callback(context).ConfigureAwait(false);\n            }\n\n            foreach (var arg in context.Args)\n            {\n                var value = await ProcessValueAsync(environmentContext, executionContext, arg).ConfigureAwait(false);\n\n                if (value is not string str)\n                {\n                    throw new NotSupportedException(\"Command line args must be strings\");\n                }\n\n                Commands.Add(new(str));\n            }\n        }\n    }\n\n    private async Task ProcessEnvironmentAsync(KubernetesEnvironmentContext environmentContext, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken)\n    {\n        if (resource.TryGetAnnotationsOfType<EnvironmentCallbackAnnotation>(out var environmentCallbacks))\n        {\n            var context = new EnvironmentCallbackContext(executionContext, resource, cancellationToken: cancellationToken);\n\n            foreach (var c in environmentCallbacks)\n            {\n                await c.Callback(context).ConfigureAwait(false);\n            }\n","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesResource.cs#L365-L401","documentation":"Thrown by ProcessArgumentsAsync in KubernetesResource when an argument reference resolves to a non-string value. During publish, all command-line arguments must be renderable as Helm string values, so any argument whose processed value is not a string is rejected with NotSupportedException.","triggerScenarios":"Using WithArgs with an expression/value provider that evaluates to a non-string (e.g. an int, bool, or custom object) instead of a string or a ReferenceExpression producing strings.","commonSituations":"Passing numeric literals or enums directly via WithArgs; a custom IValueProvider returning non-string values; version changes where an argument source stopped stringifying its output.","solutions":["Convert the argument to a string before passing it (e.g. value.ToString() or string interpolation)","Use a ReferenceExpression with string formatting so the result is a string","Implement IValueProvider such that it returns string values","Catch and log which argument produced the non-string value by inspecting context.Args"],"exampleFix":"// before\ncontainer.WithArgs(42);\n// after\ncontainer.WithArgs(42.ToString());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static string AsString(object? v) => v is string s ? s : Convert.ToString(v, CultureInfo.InvariantCulture) ?? throw new InvalidOperationException(\"Arg must be string\");","tryCatchPattern":"try { PublishAsync(...); }\ncatch (NotSupportedException ex) when (ex.Message == \"Command line args must be strings\") { /* stringify the offending arg */ }","preventionTips":["Always pass strings or ReferenceExpression to WithArgs","Make custom IValueProvider implementations return string","Add a publish test that exercises all WithArgs call sites"],"tags":["kubernetes","arguments","type-mismatch","publishing"],"backgroundTag":"type-mismatch","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"}