{"record":{"id":"c255d1efb2a2c144","repo":"microsoft/aspire","slug":"publishing-a-dotnetprojectresource-backed-blazor-gateway-is","errorCode":null,"errorMessage":"Publishing a DotnetProjectResource-backed Blazor gateway is not supported yet. Use AddBlazorGateway for publish scenarios.","messagePattern":"Publishing a DotnetProjectResource-backed Blazor gateway is not supported yet\\. Use AddBlazorGateway for publish scenarios\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs","lineNumber":112,"sourceCode":"    /// This gateway can be used only when running the AppHost. Publishing it is not supported; use the standard\n    /// Blazor gateway for publish scenarios.\n    /// </ats-remarks>\n    /// <ats-param name=\"builder\">The distributed application builder.</ats-param>\n    /// <ats-param name=\"name\">The name of the gateway resource.</ats-param>\n    /// <ats-returns>The gateway resource builder.</ats-returns>\n    [Experimental(\"ASPIREDOTNETPROJECT001\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    [AspireExport]\n    public static IResourceBuilder<DotnetProjectResource> AddDotnetProjectBlazorGateway(\n        this IDistributedApplicationBuilder builder,\n        [ResourceName] string name)\n    {\n        if (builder.ExecutionContext.IsPublishMode)\n        {\n            // A DotnetProjectResource is an ExecutableResource and is not an IContainerFilesDestinationResource,\n            // so the WASM static-asset merge that the publish path performs (via ContainerFilesDestinationAnnotation)\n            // would silently produce a gateway image missing the client apps. Fail fast instead of emitting a\n            // broken deployment until container execution is implemented for DotnetProjectResource.\n            throw new NotSupportedException(\n                $\"Publishing a {nameof(DotnetProjectResource)}-backed Blazor gateway is not supported yet. Use {nameof(AddBlazorGateway)} for publish scenarios.\");\n        }\n\n        var gatewayPath = GetScriptPath(\"Gateway.cs\");\n        return builder.AddDotnetProject(name, gatewayPath)\n            .WithHttpEndpoint()\n            .WithHttpsEndpoint();\n    }\n\n    /// <summary>\n    /// Registers a Blazor WebAssembly project as a resource using the Aspire-generated\n    /// IProjectMetadata type to discover the project path. The resource name becomes the\n    /// URL path prefix (e.g., \"store\" → served at /store/).\n    /// Use WithReference() to declare service dependencies.\n    /// </summary>\n    [AspireExportIgnore(Reason = \"Open generic type parameter TProject is not ATS-compatible.\")]\n    public static IResourceBuilder<BlazorWasmAppResource> AddBlazorWasmProject<TProject>(\n        this IDistributedApplicationBuilder builder,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs#L94-L130","documentation":"AddDotnetProjectBlazorGateway creates the Blazor gateway from a DotnetProjectResource, but publishing that shape is unsupported: the publish path's WASM static-asset merge needs IContainerFilesDestinationResource, so the resulting gateway image would silently miss client apps. The extension fails fast instead of emitting a broken deployment.","triggerScenarios":"Calling AddDotnetProjectBlazorGateway(...) inside an app model that is evaluated in publish mode (builder.ExecutionContext.IsPublishMode), e.g. running `aspire publish` against a gateway backed by AddDotnetProject.","commonSituations":"An app that runs fine locally (run mode) breaks when publishing; using the dotnet-project gateway overload for a deploy scenario where only the container-based AddBlazorGateway supports publish.","solutions":["Replace AddDotnetProjectBlazorGateway with AddBlazorGateway (container-based) for publish scenarios.","Keep the dotnet-project gateway only for local run mode and gate it with ExecutionContext checks.","Restructure so the gateway is always container-backed when publish targets are used.","Check Aspire release notes for when DotnetProjectResource container execution/publish support lands."],"exampleFix":"// before\nvar gateway = builder.AddDotnetProjectBlazorGateway(\"gateway\", ...);\n// after\nvar gateway = builder.AddBlazorGateway(\"gateway\", ...);","handlingStrategy":"validation","validationCode":"if (builder.ExecutionContext.IsPublishMode && usingDotnetProjectGateway)\n{\n    throw new InvalidOperationException(\"Use AddBlazorGateway (container-based) for publish scenarios.\");\n}","typeGuard":null,"tryCatchPattern":"try { AddGateway(builder); } catch (NotSupportedException ex) when (ex.Message.Contains(\"not supported yet\")) { logger.LogError(ex, \"Switch to AddBlazorGateway for publish\"); throw; }","preventionTips":["Use AddBlazorGateway whenever publish/deploy targets exist.","Gate dotnet-project-only wiring behind ExecutionContext.IsRunMode checks.","Track Aspire updates for DotnetProjectResource container/publish support."],"tags":["blazor","publish","unsupported-operation","gateway","wasm"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}