{"record":{"id":"57f231e5c362dbad","repo":"microsoft/aspire","slug":"chart-description-must-be-a-string-or-a-parameter-resource","errorCode":null,"errorMessage":"Chart description must be a string or a parameter resource builder.","messagePattern":"Chart description 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":271,"sourceCode":"\n        var expression = ReferenceExpression.Create($\"{description.Resource}\");\n        EnvironmentBuilder.WithAnnotation(new HelmChartDescriptionAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);\n        return this;\n    }\n\n    /// <summary>\n    /// Sets the Helm chart description written to the generated Chart.yaml.\n    /// </summary>\n    [AspireExport(MethodName = \"withChartDescription\")]\n    internal HelmChartOptions WithChartDescription([AspireUnion(typeof(string), typeof(IResourceBuilder<ParameterResource>))] object description)\n    {\n        ArgumentNullException.ThrowIfNull(description);\n\n        return description switch\n        {\n            string descriptionValue => WithChartDescription(descriptionValue),\n            IResourceBuilder<ParameterResource> descriptionParameter => WithChartDescription(descriptionParameter),\n            _ => throw new ArgumentException(\"Chart description must be a string or a parameter resource builder.\", nameof(description))\n        };\n    }\n\n    internal static void ValidateDnsLabel(string value, string target, int maxLength, string paramName)\n    {\n        if (value.Length > maxLength)\n        {\n            throw new ArgumentException($\"{target} '{value}' is invalid. It must be {maxLength} characters or fewer.\", paramName);\n        }\n\n        if (!DnsLabelPattern().IsMatch(value))\n        {\n            throw new ArgumentException($\"{target} '{value}' is invalid. Use lowercase letters, numbers, and hyphens, and start and end with an alphanumeric character.\", paramName);\n        }\n    }\n\n    internal static void ValidateNamespace(string @namespace, string paramName)\n        => ValidateDnsLabel(@namespace, \"Kubernetes namespace\", KubernetesNamespaceMaxLength, paramName);","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/HelmChartOptions.cs#L253-L289","documentation":"This error is thrown by the WithChartDescription overload accepting `object description` when the value is neither a string nor an IResourceBuilder<ParameterResource>. The Helm chart description written to Chart.yaml must be a literal string or a publish-time parameter; other types are rejected with an ArgumentException naming the `description` parameter.","triggerScenarios":"Calling WithChartDescription with an object-typed value that is not a string or IResourceBuilder<ParameterResource> — e.g. an int, bool, or a builder of the wrong resource type.","commonSituations":"Passing a config/JSON value typed as object without casting to string; passing an IResourceBuilder<ProjectResource> or similar instead of ParameterResource.","solutions":["Pass a plain string: .WithChartDescription(\"My chart description\")","Pass an IResourceBuilder<ParameterResource> from builder.AddParameter(...)","Convert the object value to string (or ToString()) before calling the API"],"exampleFix":"// before\nobject desc = GetDescription();\n.WithChartDescription(desc) // throws\n// after\nstring desc = GetDescription().ToString()!;\n.WithChartDescription(desc)","handlingStrategy":"type-guard","validationCode":"public static bool IsValidChartDescriptionArg(object? d) => d is string or IResourceBuilder<ParameterResource>;","typeGuard":"var ok = d is string || d is IResourceBuilder<ParameterResource>;","tryCatchPattern":"try { chart.WithChartDescription(descValue); }\ncatch (ArgumentException ex) when (ex.ParamName == \"description\") { /* use a default description or rethrow with context */ }","preventionTips":["Type description variables as string","Call .ToString() on config-derived values before passing them","Prefer builder.AddParameter over loosely typed values for dynamic descriptions"],"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"}