Skip to content

Using MapGroup with Blazor endpoints produces template error #64965

@ptsoccer

Description

@ptsoccer

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Similar to #57843, but when I use MapGroup to map blazor endpoints to a different base path, I get the error:

InvalidOperationException: Unable to find the provided template '/blazor/'

In the blazor template, I replace

app.MapStaticAssets();
app.MapRazorComponents<App>()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);

with

var groupBuilder = app.MapGroup("/blazor");

groupBuilder
    .MapStaticAssets();

groupBuilder
    .MapRazorComponents<App>()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);

I suppose the first question is, is that a valid thing to do? The issue I mentioned above does it using UsePathBase, but it seemed better to do what I want with the newer MapGroup feature.

Expected Behavior

Blazor site loads in new base path

Steps To Reproduce

Repo: https://github.com/ptsoccer/BlazorBasePath

  1. Create new Blazor Web App with WebAssembly as the interactive render mode. Other render modes might also error out, but I need WebAssembly.
  2. Replace
app.MapStaticAssets();
app.MapRazorComponents<App>()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);

with

var groupBuilder = app.MapGroup("/blazor");

groupBuilder
    .MapStaticAssets();

groupBuilder
    .MapRazorComponents<App>()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(BlazorBasePath.Client._Imports).Assembly);

in the generated template

  1. Run the website and browse to /blazor, you should get the error mentioned above.

Exceptions (if any)

No response

.NET Version

10.0.101

Anything else?

Microsoft.NETCore.App 10.0.1
Microsoft.AspNetCore.App 10.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions