microsoft/aspire · error · InvalidOperationException

Dashboard resource is not initialized

Error message

Dashboard resource is not initialized

What it means

WithDashboard enables the compose environment's dashboard and then configures it via the callback. If DashboardEnabled was never materialized into a Dashboard resource (it is null) the method throws InvalidOperationException, since there is nothing to configure. This typically means the dashboard resource was not initialized before WithDashboard was called.

Solutions

  1. Ensure dashboard support is enabled through the supported API path so Resource.Dashboard gets initialized before calling WithDashboard.
  2. Update the Aspire.Hosting.Docker package if a version bug skipped dashboard initialization.
  3. If you do not need dashboard configuration, omit the WithDashboard call entirely (setting DashboardEnabled alone does not create it).

Example fix

// before (Dashboard not initialized)
var env = builder.AddDockerComposeEnvironment("env");
env.WithDashboard(d => d.WithHost("0.0.0.0"));
// after: use the current API which initializes the dashboard when enabling it, e.g.
var env = builder.AddDockerComposeEnvironment("env").WithDashboard(d => d.WithHost("0.0.0.0"));
Defensive patterns

Strategy: type-guard

Type guard

if (env.Resource.Dashboard is { } dashboard)
{
    configure(dashboard);
}
else
{
    // dashboard not initialized; enable via the supported API path before configuring
}

Prevention

When it happens

Trigger: Calling WithDockerComposeDashboard/WithDashboard on a DockerComposeEnvironmentBuilder whose Resource.Dashboard is null — e.g. the dashboard resource is only created later or in a code path not executed for this environment.

Common situations: Calling dashboard configuration at the wrong point in the builder chain or in an older/broken code path where dashboard initialization was skipped; environment constructed manually or deserialized rather than through the standard factory.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Docker/DockerComposeEnvironmentExtensions.cs:199

    }

    /// <summary>
    /// Configures the dashboard properties for this Docker Compose environment.
    /// </summary>
    /// <param name="builder">The Docker Compose environment resource builder.</param>
    /// <param name="configure">A method that can be used for customizing the dashboard service.</param>
    /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
    /// <ats-returns>The resource builder.</ats-returns>
    [AspireExport("configureDashboard", MethodName = "configureDashboard", RunSyncOnBackgroundThread = true)]
    public static IResourceBuilder<DockerComposeEnvironmentResource> WithDashboard(this IResourceBuilder<DockerComposeEnvironmentResource> builder, Action<IResourceBuilder<DockerComposeAspireDashboardResource>> configure)
    {
        ArgumentNullException.ThrowIfNull(builder);
        ArgumentNullException.ThrowIfNull(configure);

        // Ensure the dashboard resource is initialized
        builder.Resource.DashboardEnabled = true;

        configure(builder.Resource.Dashboard ?? throw new InvalidOperationException("Dashboard resource is not initialized"));

        return builder;
    }
}

View on GitHub (pinned to 25830f84bd)