microsoft/aspire · error · ArgumentException
Chart description must be a string or a parameter resource…
Error message
Chart description must be a string or a parameter resource builder.
What it means
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.
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
Example fix
// before object desc = GetDescription(); .WithChartDescription(desc) // throws // after string desc = GetDescription().ToString()!; .WithChartDescription(desc)
Defensive patterns
Strategy: type-guard
Validate before calling
public static bool IsValidChartDescriptionArg(object? d) => d is string or IResourceBuilder<ParameterResource>;
Type guard
var ok = d is string || d is IResourceBuilder<ParameterResource>;
Try / catch
try { chart.WithChartDescription(descValue); }
catch (ArgumentException ex) when (ex.ParamName == "description") { /* use a default description or rethrow with context */ } Prevention
- Type description variables as string
- Call .ToString() on config-derived values before passing them
- Prefer builder.AddParameter over loosely typed values for dynamic descriptions
When it happens
Trigger: 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.
Common situations: Passing a config/JSON value typed as object without casting to string; passing an IResourceBuilder<ProjectResource> or similar instead of ParameterResource.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Chart name must be a string or a parameter resource builder.
- Cannot derive a Helm release name from resource name
- Cannot derive a Kubernetes namespace from resource name
- Chart version must be a string or a parameter resource…
- Could not parse Helm version from 'helm version --short'…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/57f231e5c362dbad.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Kubernetes/HelmChartOptions.cs:271
var expression = ReferenceExpression.Create($"{description.Resource}");
EnvironmentBuilder.WithAnnotation(new HelmChartDescriptionAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);
return this;
}
/// <summary>
/// Sets the Helm chart description written to the generated Chart.yaml.
/// </summary>
[AspireExport(MethodName = "withChartDescription")]
internal HelmChartOptions WithChartDescription([AspireUnion(typeof(string), typeof(IResourceBuilder<ParameterResource>))] object description)
{
ArgumentNullException.ThrowIfNull(description);
return description switch
{
string descriptionValue => WithChartDescription(descriptionValue),
IResourceBuilder<ParameterResource> descriptionParameter => WithChartDescription(descriptionParameter),
_ => throw new ArgumentException("Chart description must be a string or a parameter resource builder.", nameof(description))
};
}
internal static void ValidateDnsLabel(string value, string target, int maxLength, string paramName)
{
if (value.Length > maxLength)
{
throw new ArgumentException($"{target} '{value}' is invalid. It must be {maxLength} characters or fewer.", paramName);
}
if (!DnsLabelPattern().IsMatch(value))
{
throw new ArgumentException($"{target} '{value}' is invalid. Use lowercase letters, numbers, and hyphens, and start and end with an alphanumeric character.", paramName);
}
}
internal static void ValidateNamespace(string @namespace, string paramName)
=> ValidateDnsLabel(@namespace, "Kubernetes namespace", KubernetesNamespaceMaxLength, paramName);View on GitHub (pinned to 25830f84bd)