microsoft/aspire · error · InvalidOperationException
Dashboard resource is not initialized
Error message
Dashboard resource is not initialized
What it means
WithDashboard enables the dashboard on a Kubernetes environment and then invokes the caller's configure callback on Resource.Dashboard. If the Dashboard resource was never initialized on the environment resource, the null-check throws InvalidOperationException.
Solutions
- Ensure the environment creates its dashboard resource (check how the environment is constructed; do not bypass standard AddKubernetesEnvironment wiring).
- Call WithDashboard only after the dashboard resource is initialized.
- Guard the callback behind a null check on Dashboard if dashboard presence is optional.
Example fix
// before
env.WithDashboard(d => d.WithReplicas(2)); // Dashboard not initialized
// after
if (env.Resource.Dashboard is not null)
{
env.WithDashboard(d => d.WithReplicas(2));
} Defensive patterns
Strategy: type-guard
Validate before calling
if (env.Resource.Dashboard is null) throw new InvalidOperationException("Dashboard not initialized; check environment construction."); Type guard
static bool HasDashboard(KubernetesEnvironmentBuilder env) => env.Resource.Dashboard is not null;
Try / catch
try { env.WithDashboard(d => ...); } catch (InvalidOperationException ex) when (ex.Message == "Dashboard resource is not initialized") { /* initialize dashboard first or skip */ } Prevention
- Use the standard AddKubernetesEnvironment flow so the dashboard is created
- Verify Dashboard is non-null before configuring
- Follow updated samples when the dashboard API changes
When it happens
Trigger: Calling WithDashboard(env => ...) on a KubernetesEnvironmentResource whose Dashboard property is null — i.e. the dashboard resource was not created during environment construction/configuration.
Common situations: Calling WithDashboard before the dashboard is created, or on an environment constructed/configured in a way that skips dashboard initialization; stale code after the dashboard creation API changed.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Dashboard resource is not initialized
- Historical dashboard data is read-only.
- A ConfigureRadiusInfrastructure callback left container
- Already connected to
- AppHost:ResourceService:ApiKey is not specified in…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/e725e4aa5568c4d1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentExtensions.cs:450
/// Configures the dashboard properties for this Kubernetes environment.
/// </summary>
/// <param name="builder">The Kubernetes environment resource builder.</param>
/// <param name="configure">A method that can be used for customizing the dashboard resource.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
/// <ats-returns>The resource builder.</ats-returns>
/// <remarks>
/// Use this overload to customize the dashboard container, for example to set a specific host port
/// or enable forwarded headers for ingress access.
/// </remarks>
[AspireExport("configureDashboard", MethodName = "configureDashboard", RunSyncOnBackgroundThread = true)]
public static IResourceBuilder<KubernetesEnvironmentResource> WithDashboard(this IResourceBuilder<KubernetesEnvironmentResource> builder, Action<IResourceBuilder<KubernetesAspireDashboardResource>> configure)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);
builder.Resource.DashboardEnabled = true;
configure(builder.Resource.Dashboard ?? throw new InvalidOperationException("Dashboard resource is not initialized"));
return builder;
}
/// <summary>
/// Adds a named node pool to the Kubernetes environment.
/// </summary>
/// <param name="builder">The Kubernetes environment resource builder.</param>
/// <param name="name">The name of the node pool. This value is used as the <c>nodeSelector</c> value.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{KubernetesNodePoolResource}"/> for the new node pool.</returns>
/// <ats-returns>The resource builder.</ats-returns>
/// <remarks>
/// For vanilla Kubernetes, this creates a named reference to an existing node pool.
/// For managed Kubernetes services (e.g., AKS), the cloud-specific <c>AddNodePool</c> overload
/// provisions the pool with additional configuration such as VM size and autoscaling.
/// Use <see cref="WithNodePool{T}"/> to schedule workloads on the returned node pool.
/// </remarks>
/// <example>View on GitHub (pinned to 25830f84bd)