microsoft/aspire · error · InvalidOperationException

rad credential register failed with exit code

Error message

rad credential register failed with exit code {process.ExitCode}: {stderr.ToString().Trim()}

What it means

After running the `rad credential register` CLI process, a non-zero exit code means Radius rejected the credential registration. The step logs the combined stderr and throws an InvalidOperationException containing the exit code and stderr text.

Solutions

  1. Read the stderr text in the message; fix the underlying rad error (wrong context, auth failure, malformed credential).
  2. Run `rad env list` / `rad credential list` manually to verify the CLI can reach the intended Radius installation.
  3. Re-login or refresh credentials (`az login`, kubeconfig) and re-run the publish/deploy.
  4. Ensure the installed rad CLI version matches your Radius control plane version.

Example fix

// before (shell)
rad credential register azure --from-env-file stale-creds.json
// fails: exit code 1, 'unable to connect to control plane'

// after (shell)
rad env switch my-radius-env && az login && rad credential register azure --from-env-file creds.json
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: verify the rad CLI can reach the control plane before publishing
var psi = new ProcessStartInfo("rad", "env list") { RedirectStandardError = true };
using var p = Process.Start(psi)!;
await p.WaitForExitAsync();
if (p.ExitCode != 0) throw new InvalidOperationException($"rad CLI pre-flight failed: {await p.StandardError.ReadToEndAsync()}");

Try / catch

try { await publishOperation.ExecuteAsync(ct); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("rad credential register failed"))
{
    logger.LogError(ex, "Credential registration failed; check rad context, login state, and credential file contents.");
}

Prevention

When it happens

Trigger: Executing ExecuteAsync on RadCredentialRegisterStep when the rad CLI exits non-zero, e.g. the Radius environment/context is not initialized, the credential payload is invalid, or authentication to the control plane fails.

Common situations: rad CLI not logged in or pointed at the wrong Radius context; credential secret file malformed or expired; Kubernetes cluster / Radius control plane unreachable; version mismatch between rad CLI and installed Radius.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Radius/Publishing/RadCredentialRegisterStep.cs:330

                logger.LogWarning("Cancellation requested — terminating rad credential register process.");
                try
                {
                    process.Kill(entireProcessTree: true);
                }
                catch (InvalidOperationException)
                {
                    // Race: the process exited between the HasExited check and Kill. Nothing to do.
                }
            }

            throw;
        }

        if (process.ExitCode != 0)
        {
            var msg = $"rad credential register failed with exit code {process.ExitCode}: {stderr.ToString().Trim()}";
            logger.LogError("{Message}", msg);
            throw new InvalidOperationException(msg);
        }
    }

    internal static IReadOnlyList<string> RedactSecretArgs(
        IReadOnlyList<string> args, HashSet<string> secretFlags)
    {
        var result = new List<string>(args.Count);
        for (var i = 0; i < args.Count; i++)
        {
            result.Add(args[i]);
            if (secretFlags.Contains(args[i]) && i + 1 < args.Count)
            {
                result.Add("***");
                i++;
            }
        }
        return result;
    }

View on GitHub (pinned to 25830f84bd)