{"record":{"id":"e725e4aa5568c4d1","repo":"microsoft/aspire","slug":"dashboard-resource-is-not-initialized-e725e4","errorCode":null,"errorMessage":"Dashboard resource is not initialized","messagePattern":"Dashboard resource is not initialized","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentExtensions.cs","lineNumber":450,"sourceCode":"    /// Configures the dashboard properties for this Kubernetes environment.\n    /// </summary>\n    /// <param name=\"builder\">The Kubernetes environment resource builder.</param>\n    /// <param name=\"configure\">A method that can be used for customizing the dashboard resource.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    /// <remarks>\n    /// Use this overload to customize the dashboard container, for example to set a specific host port\n    /// or enable forwarded headers for ingress access.\n    /// </remarks>\n    [AspireExport(\"configureDashboard\", MethodName = \"configureDashboard\", RunSyncOnBackgroundThread = true)]\n    public static IResourceBuilder<KubernetesEnvironmentResource> WithDashboard(this IResourceBuilder<KubernetesEnvironmentResource> builder, Action<IResourceBuilder<KubernetesAspireDashboardResource>> configure)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(configure);\n\n        builder.Resource.DashboardEnabled = true;\n\n        configure(builder.Resource.Dashboard ?? throw new InvalidOperationException(\"Dashboard resource is not initialized\"));\n\n        return builder;\n    }\n\n    /// <summary>\n    /// Adds a named node pool to the Kubernetes environment.\n    /// </summary>\n    /// <param name=\"builder\">The Kubernetes environment resource builder.</param>\n    /// <param name=\"name\">The name of the node pool. This value is used as the <c>nodeSelector</c> value.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{KubernetesNodePoolResource}\"/> for the new node pool.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    /// <remarks>\n    /// For vanilla Kubernetes, this creates a named reference to an existing node pool.\n    /// For managed Kubernetes services (e.g., AKS), the cloud-specific <c>AddNodePool</c> overload\n    /// provisions the pool with additional configuration such as VM size and autoscaling.\n    /// Use <see cref=\"WithNodePool{T}\"/> to schedule workloads on the returned node pool.\n    /// </remarks>\n    /// <example>","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentExtensions.cs#L432-L468","documentation":"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.","triggerScenarios":"Calling WithDashboard(env => ...) on a KubernetesEnvironmentResource whose Dashboard property is null — i.e. the dashboard resource was not created during environment construction/configuration.","commonSituations":"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.","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."],"exampleFix":"// before\nenv.WithDashboard(d => d.WithReplicas(2)); // Dashboard not initialized\n// after\nif (env.Resource.Dashboard is not null)\n{\n    env.WithDashboard(d => d.WithReplicas(2));\n}","handlingStrategy":"type-guard","validationCode":"if (env.Resource.Dashboard is null) throw new InvalidOperationException(\"Dashboard not initialized; check environment construction.\");","typeGuard":"static bool HasDashboard(KubernetesEnvironmentBuilder env) => env.Resource.Dashboard is not null;","tryCatchPattern":"try { env.WithDashboard(d => ...); } catch (InvalidOperationException ex) when (ex.Message == \"Dashboard resource is not initialized\") { /* initialize dashboard first or skip */ }","preventionTips":["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"],"tags":["kubernetes","dashboard","invalid-state","null"],"backgroundTag":"internal-invariant-violation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}