microsoft/aspire · error · ArgumentNullException

adminPassword

Error message

adminPassword

What it means

KeycloakResource's constructor requires an admin password parameter resource. When the adminPassword argument is null, the property initializer throws ArgumentNullException(nameof(adminPassword)). This ensures every Keycloak resource always has a ParameterResource that supplies the admin password at runtime.

Solutions

  1. Create a parameter with builder.AddParameter("keycloak-admin-password", secret: true) and pass it as adminPassword.
  2. Use the standard AddKeycloak extension which supplies the parameter automatically.
  3. If you need a generated password, use ParameterResource with a generated default value rather than null.

Example fix

// before
var kc = new KeycloakResource("keycloak", adminPassword: null);

// after
var password = builder.AddParameter("keycloak-admin-password", secret: true);
var kc = new KeycloakResource("keycloak", password);
Defensive patterns

Strategy: validation

Validate before calling

if (adminPassword is null) throw new ArgumentNullException(nameof(adminPassword)); // check before constructing KeycloakResource

Type guard

bool HasPassword(KeycloakResource r) => r.AdminPasswordParameter is not null;

Prevention

When it happens

Trigger: Constructing KeycloakResource directly, or calling the AddKeycloak overload with a null adminPassword parameter resource.

Common situations: Developers write custom factory code that creates a KeycloakResource without wiring up a password parameter, or accidentally pass null instead of builder.AddParameter("...") result.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Keycloak/KeycloakResource.cs:42

    /// <summary>
    /// Features to disable for the keycloak resource
    /// </summary>
    internal HashSet<string> DisabledFeatures { get; } = new();

    /// <summary>
    /// Gets the parameter that contains the Keycloak admin.
    /// </summary>
    public ParameterResource? AdminUserNameParameter { get; } = admin;

    internal ReferenceExpression AdminReference =>
        AdminUserNameParameter is not null ?
            ReferenceExpression.Create($"{AdminUserNameParameter}") :
            ReferenceExpression.Create($"{DefaultAdmin}");

    /// <summary>
    /// Gets the parameter that contains the Keycloak admin password.
    /// </summary>
    public ParameterResource AdminPasswordParameter { get; } = adminPassword ?? throw new ArgumentNullException(nameof(adminPassword));
}

View on GitHub (pinned to 25830f84bd)