Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove Counter from .Net 8 Blazor template

I just created my first .Net 8 Blazor Web App using the new template. I want to remove the Counter, as I will be modifying the app for my own purposes. I run into a problem when I remove the last line of the following boilerplate code:

    app.MapRazorComponents<App>()
        .AddInteractiveServerRenderMode()
        .AddInteractiveWebAssemblyRenderMode()
        .AddAdditionalAssemblies(typeof(Counter).Assembly);

Remove that line, then run the app and you get a 404. Put it back, and it runs fine.

How do I get rid of the counter code? It’s driving me nuts!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Look closely at that line. It says typeof(Counter).Assembly.

You’re not removing counter, your removing the instruction for the SSR Razor/Blazor to read any routes [defined by "@page …"] in the assembly to which Counter belongs.

That line:

.AddAdditionalAssemblies(typeof(Counter).Assembly);

Needs to refer any object in the Client Project.

In this example the solution is called SO77672168 [your question ID].

This line:

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(SO77672168.Client._Imports).Assembly);

Adds the middleware to the Http request pipeline, and instructs the server side router to not only look in it’s own assembly for routes, but also in the assembly to which SO77672168.Client._Imports belongs.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading