{"record":{"id":"6ae2f5578c7869ce","repo":"microsoft/aspire","slug":"chart-version-must-be-a-string-or-a-parameter-resource","errorCode":null,"errorMessage":"Chart version must be a string or a parameter resource builder.","messagePattern":"Chart version 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":177,"sourceCode":"\n        var expression = ReferenceExpression.Create($\"{version.Resource}\");\n        EnvironmentBuilder.WithAnnotation(new HelmChartVersionAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);\n        return this;\n    }\n\n    /// <summary>\n    /// Sets the Helm chart version for deployment.\n    /// </summary>\n    [AspireExport(MethodName = \"withChartVersion\")]\n    internal HelmChartOptions WithChartVersion([AspireUnion(typeof(string), typeof(IResourceBuilder<ParameterResource>))] object version)\n    {\n        ArgumentNullException.ThrowIfNull(version);\n\n        return version switch\n        {\n            string versionValue => WithChartVersion(versionValue),\n            IResourceBuilder<ParameterResource> versionParameter => WithChartVersion(versionParameter),\n            _ => throw new ArgumentException(\"Chart version must be a string or a parameter resource builder.\", nameof(version))\n        };\n    }\n\n    /// <summary>\n    /// Sets the Helm chart name written to the generated <c>Chart.yaml</c>.\n    /// </summary>\n    /// <param name=\"name\">The chart name. Must match Helm's chart-name format (alphanumeric, <c>-</c>, <c>_</c>, or <c>.</c>).</param>\n    /// <returns>This <see cref=\"HelmChartOptions\"/> for chaining.</returns>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the union-based withChartName dispatcher export.\")]\n    public HelmChartOptions WithChartName(string name)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(name);\n        ValidateChartName(name, nameof(name));\n\n        var expression = ReferenceExpression.Create($\"{name}\");\n        EnvironmentBuilder.WithAnnotation(new HelmChartNameAnnotation(expression), ResourceAnnotationMutationBehavior.Replace);\n        return this;\n    }","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/HelmChartOptions.cs#L159-L195","documentation":"WithChartVersion(object) accepts either a string chart version or an IResourceBuilder<ParameterResource>; any other type throws ArgumentException. Like the other HelmChartOptions overloads, a type-switch narrows to the strongly-typed implementations and rejects everything else.","triggerScenarios":"Calling .WithChartVersion() with a value whose runtime type is neither string nor IResourceBuilder<ParameterResource> (e.g. a Version object, a double like 1.2, or a wrapper).","commonSituations":"Passing a System.Version or numeric version instead of a SemVer string; passing a parameter value instead of a parameter resource builder; value typed as object from configuration.","solutions":["Pass a version string: .WithChartVersion(\"1.2.3\").","Pass an IResourceBuilder<ParameterResource> created with builder.AddParameter(...).","Convert non-string version representations to a SemVer string before calling."],"exampleFix":"// before\nhelmOptions.WithChartVersion(new Version(1, 2, 3));\n// after\nhelmOptions.WithChartVersion(\"1.2.3\");\n// or\nvar versionParam = builder.AddParameter(\"chartVersion\");\nhelmOptions.WithChartVersion(versionParam);","handlingStrategy":"type-guard","validationCode":"bool isValidChartVersionArg(object? value) => value is string or IResourceBuilder<ParameterResource>;","typeGuard":"static bool IsChartVersionArg(object? value) => value is string or IResourceBuilder<ParameterResource>;","tryCatchPattern":"try { options.WithChartVersion(value); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Chart version must be a string or IResourceBuilder<ParameterResource>\"); }","preventionTips":["Always supply chart versions as SemVer strings, not Version or numeric objects.","Use builder.AddParameter() for dynamic versions.","Avoid object-typed variables when configuring Helm chart options."],"tags":["kubernetes","helm","chart-version","argument"],"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"}