microsoft/aspire · error · InvalidOperationException

helm upgrade --install for chart

Error message

helm upgrade --install for chart '{chart.Name}' failed with exit code {exitCode}

What it means

InstallHelmChartAsync runs 'helm upgrade --install' for the chart and throws InvalidOperationException when the helm process exits with a non-zero exit code. If helm captured stderr, that error output is included in the message; otherwise only the exit code is reported.

Solutions

  1. Read the included helm stderr output in the exception message for the root cause
  2. Run the same 'helm upgrade --install' command manually against the cluster to see full diagnostics
  3. Verify kubeconfig/context and cluster connectivity (kubectl cluster-info)
  4. Fix chart values or templates that helm rejects
  5. Delete/reset a broken prior helm release before reinstalling
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-checks before install
if (string.IsNullOrWhiteSpace(chart.Path) || !File.Exists(chart.Path))
    throw new FileNotFoundException("Helm chart not found.", chart.Path);
var psi = new ProcessStartInfo("helm", "version --short"); // verify helm + cluster reachability

Try / catch

try { await InstallHelmChartAsync(chart, ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("helm upgrade --install"))
{ logger.LogError(ex, "Helm install failed: {Detail}", ex.Message); }

Prevention

When it happens

Trigger: helm upgrade --install returns non-zero: invalid chart or values, unreachable cluster, missing kubeconfig context, existing release with a conflicting revision, insufficient RBAC, or helm not finding resources it expects.

Common situations: Cluster unreachable/wrong context; chart values failing schema validation; a previous failed release in a broken state; namespace missing or RBAC denied; image pull failures surfacing through helm hooks.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/ec91005ed7636f0a. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs:362

        var exitCode = await helmRunner.RunAsync(
            arguments.ToString(),
            onOutputData: output => logger.LogDebug("helm (stdout): {Output}", output),
            onErrorData: error =>
            {
                stderrBuilder.AppendLine(error);
                logger.LogDebug("helm (stderr): {Error}", error);
            },
            cancellationToken: context.CancellationToken).ConfigureAwait(false);

        if (exitCode != 0)
        {
            var errorOutput = stderrBuilder.ToString().Trim();
            var message = string.IsNullOrEmpty(errorOutput)
                ? $"helm upgrade --install for chart '{chart.Name}' failed with exit code {exitCode}"
                : $"helm upgrade --install for chart '{chart.Name}' failed: {errorOutput}";

            throw new InvalidOperationException(message);
        }

        if (chart.DestroyOnUninstall)
        {
            // Persist install state so destroy can find this release later, even from a
            // different process where the in-memory resource state is gone.
            var deploymentStateManager = context.Services.GetRequiredService<IDeploymentStateManager>();
            var stateSection = await deploymentStateManager
                .AcquireSectionAsync(GetStateSectionName(environment, chart), context.CancellationToken)
                .ConfigureAwait(false);
            stateSection.Data["ReleaseName"] = releaseName;
            stateSection.Data["Namespace"] = @namespace;
            await deploymentStateManager.SaveSectionAsync(stateSection, context.CancellationToken).ConfigureAwait(false);
        }

        logger.LogInformation(
            "Helm chart '{ChartName}' installed successfully as release '{ReleaseName}' in namespace '{Namespace}'.",
            chart.Name, releaseName, @namespace);

View on GitHub (pinned to 25830f84bd)