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
- Create a parameter with builder.AddParameter("keycloak-admin-password", secret: true) and pass it as adminPassword.
- Use the standard AddKeycloak extension which supplies the parameter automatically.
- 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
- Use the AddKeycloak extension rather than constructing KeycloakResource manually.
- Create password parameters with builder.AddParameter(..., secret: true).
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
- Array params contains null item
- The API key parameter must be marked as secret. Use…
- Value cannot be null. (Parameter 'iconName')
- Value cannot be null. (Parameter 'innerResource')
- Value cannot be null. (Parameter 'logger')
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)