{"record":{"id":"ede4eeb33acd9ea4","repo":"microsoft/aspire","slug":"chart-name-must-be-a-string-or-a-parameter-resource-builder","errorCode":null,"errorMessage":"Chart name must be a string or a parameter resource builder.","messagePattern":"Chart name must be a string or a parameter resource builder\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/HelmChartOptions.cs","lineNumber":224,"sourceCode":"\n        var expression = ReferenceExpression.Create($\"{name.Resource}\");\n        EnvironmentBuilder.WithAnnotation(new HelmChartNameAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);\n        return this;\n    }\n\n    /// <summary>\n    /// Sets the Helm chart name written to the generated Chart.yaml.\n    /// </summary>\n    [AspireExport(MethodName = \"withChartName\")]\n    internal HelmChartOptions WithChartName([AspireUnion(typeof(string), typeof(IResourceBuilder<ParameterResource>))] object name)\n    {\n        ArgumentNullException.ThrowIfNull(name);\n\n        return name switch\n        {\n            string nameValue => WithChartName(nameValue),\n            IResourceBuilder<ParameterResource> nameParameter => WithChartName(nameParameter),\n            _ => throw new ArgumentException(\"Chart name must be a string or a parameter resource builder.\", nameof(name))\n        };\n    }\n\n    /// <summary>\n    /// Sets the Helm chart description written to the generated <c>Chart.yaml</c>.\n    /// </summary>\n    /// <param name=\"description\">The chart description.</param>\n    /// <returns>This <see cref=\"HelmChartOptions\"/> for chaining.</returns>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the union-based withChartDescription dispatcher export.\")]\n    public HelmChartOptions WithChartDescription(string description)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(description);\n        ValidateChartDescription(description, nameof(description));\n\n        var expression = ReferenceExpression.Create($\"{description}\");\n        EnvironmentBuilder.WithAnnotation(new HelmChartDescriptionAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);\n        return this;\n    }","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/HelmChartOptions.cs#L206-L242","documentation":"This error is thrown by the WithChartName overload that accepts `object name` when the value is neither a string nor an IResourceBuilder<ParameterResource>. The Kubernetes publishing API requires the Helm chart name to be either a literal string or a parameter resource so it can be resolved at publish time; anything else is rejected. It is an ArgumentException naming the `name` parameter.","triggerScenarios":"Calling WithChartName with a value whose compile-time type is object (or a dynamic value) that is not a string or IResourceBuilder<ParameterResource> — e.g. passing an int, a char, or a builder of the wrong resource type.","commonSituations":"Developers pass a variable typed as object (read from configuration or deserialized JSON) into WithChartName without casting to string; or they pass an IResourceBuilder of a non-Parameter resource type assuming it is accepted.","solutions":["Pass a plain string: builder.PublishAsKubernetesHelmChart(...).WithChartName(\"mychart\")","Pass an IResourceBuilder<ParameterResource> obtained from builder.AddParameter(\"chart-name\")","If the value comes in as object, cast or convert to string first (e.g. obj as string ?? throw) before calling WithChartName"],"exampleFix":"// before\nobject chartName = config[\"ChartName\"];\n.WithChartName(chartName) // throws\n// after\nstring chartName = config[\"ChartName\"]!;\n.WithChartName(chartName)","handlingStrategy":"type-guard","validationCode":"public static bool IsValidChartNameArg(object? name) => name is string or IResourceBuilder<ParameterResource>;","typeGuard":"var ok = name is string || name is IResourceBuilder<ParameterResource>;","tryCatchPattern":"try { chart.WithChartName(nameValue); }\ncatch (ArgumentException ex) when (ex.ParamName == \"name\") { /* fall back to a default chart name or fail fast with a clear message */ }","preventionTips":["Keep chart-name variables typed as string, never object","Use builder.AddParameter for dynamic names instead of boxing values","Enable nullable reference types so accidental object-typed values stand out"],"tags":["kubernetes","helm","argument-validation"],"backgroundTag":"invalid-argument-value","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"}