Skip to content

Blazor Server sites break when ASPNETCORE_ENVIRONMENT is set to anything other than Development, Staging, or Production #55426

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


I had a Blazor Server site started in .NET6 that was upgraded to 7 then to 8. I changed the ASPNETCORE_ENVIRONMENT to "Local". The site stopped working. It would load the initial HTML, but none of the interactivity was there and none of the CSS styles were there.

The community on reddit (/r/Blazor) helped me understand that I needed the below statement in my program.cs.

StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);

It is unclear to me if this is a bug in Blazor or ASPNET Core, or if it's not a bug and just deep knowledge that a programmer is expected to have. Regardless, Visual Studio could detect and warn about this. If the ASPNETCORE_ENVIRONMENT variable is set to a non-standard value, warn the programmer that they need to configure static web assets.

This issue is easy to reproduce. Start a Blazor Server project from template and change the environment variable and you will see the issue. Add the above statement and you will observe the issue as resolved.


Original Comments

Miller, Michael on 1/8/2024, 06:45 AM:

(private comment, text removed)

Feedback Bot on 1/8/2024, 09:36 PM:

(private comment, text removed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Author: Migration Bot 🤖The issue was created by a issue mover bot. The author may not be the actual author.Pillar: Dev ExperienceanalyzerIndicates an issue which is related to analyzer experiencearea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions