aspnetcore: .net8 preview 4: Hosting environment not detected via Blazor-Environment header

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We have an existing webassembly app that works 100% on preview 3. We select different runtime configurations by setting the Blazor-Environment header on the webserver to select the correct appsettings.{environment}.json file.

After upgrading to preview 4 the environment is not detected and reverts to the default Production

We have verified that the server still returns the correct header as previously.

Downgrading same to preview 3 still works in same environment.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.100-preview.4.23260.5

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 18 (16 by maintainers)

Most upvoted comments

@JeepNL Sorry for the delayed reply. Thank you very much for the detailed repro steps. I was able to reproduce the issue. We made a lot of changes in this area, and it looks like appsettings.json and appsettings.Development.json are no longer compressed by default.

I was able to make things work by adding the following to the .csproj file. Could you please try the same, and confirm if it resolves the issue on your end?

<PropertyGroup>
  <CompressionIncludePatterns>$(CompressionIncludePatterns);appsettings*.json</CompressionIncludePatterns>
</PropertyGroup>

@javiercn Do you think we should change things so appsettings.json files are explicitly compressed by default? This would be consistent with how compression worked in the past.

@MackinnonBuck No problem for the delayed reply, MS Build is happening too, so you all are probably very busy!

And yes, your solution works! Perfectly!

When I ‘dotnet publish -c Release’ the project, the compressed appsettings*.json files (.br and .gz) are automatically generated.

@MackinnonBuck I’ve spent the whole weekend (and last Friday) investigating this, and today, Sunday 8 PM, I finally got it working. The error is very easy to reproduce. I’ve made a public GitHub Repo for you to try: https://github.com/JeepNL/StaticBlazorWasm

Standalone (Static) Blazor WASM Production Error

.NET 8 Preview 5 (nightly build) expects a appsettings.json.br, but it isn’t there. Only files in _framework are Brotli compressed. The appsettings.json is not. Note: not locally, only when you deployed the site to GitHub Pages.

Without manually adding a Brotli compressed appsettings.json.br the site won’t run when deployed.

To Reproduce:

(my repo has everything that is needed)

  1. You need to have a appsettings.json file in the wwwroot directory of the Static Standalone Blazor WASM app
  2. You need to access a value from appsettings.json in a .razor page like index.razor
  3. You have to enable Brotli compression in index.html
  4. You have to publish (release) the project to GitHub Pages. Only then the error show ups. Always.

Live GitHub Pages Demo

I’ve also a live .NET 8 preview 5 (static) Standalone Blazor WASM GitHub Pages working demo site running here: https://jeepnl.github.io/StaticBlazorWasmPrebuilt/

If you use developer tools, you’ll see the site needs a appsettings.json.br

This demo site doesn’t use GitHub Workflow Actions, I’ve built the site locally on my Windows 11 Desktop PC, and deployed, using GitHub Desktop, the contents of the wwwroot folder to GitHub, and enabled GitHub Pages.

.NET 8 Preview 5 nightly build (dotnet-sdk-8.0.100-preview.5.23271.2)

I’ve used .NET 8 Preview 5 nightly build because you said you weren’t able to reproduce it with that version. With .NET 8 Preview 4 I’m also not able to get a static Standalone Blazor WASM site up and running (which uses a value from appsettings.json). It’s problematic because, in appsettings.json I’ve defined the value of my back-end API server for my production website.

Workloads wasm-tools and wasm-experimental are installed (and updated) too.

To run locally (no error in this case …):

  • you have to uncomment <!-- <base href="/" /> --> in index.html and comment out: <base href="/StaticBlazorWasmPrebuilt/" />

Note:

To run locally, in StaticBlazorWasm.csproj i’m using:

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-preview.4.23260.4" PrivateAssets="all" />

instead of

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-preview.5.23271.1" PrivateAssets="all" />

because it only runs locally with the .NET 8 Preview 4 version

The Good News

I got my ‘production’ static standalone Blazor WASM website https://Tusk.Ninja (Tools for Mastodon) up and running on Cloudflare Pages with dotnet-sdk-8.0.100-preview.5.23271.2 and with manually compressing appsettings.json to Brotli and GZip.

I don’t know if I need to create a separate issue with the Brotli error, please advise .

@JeepNL, thank you for the repro!

@MackinnonBuck , could you please confirm if the Brotli error is related to your changes?

I’m seeing the same thing @JeepNL is seeing as well. The strange thing about it though is that it’s not happening all of the time. It’s very hard to pinpoint down where it’s failing, but this is where I’m seeing it start to throw the error:

https://github.com/dotnet/aspnetcore/blob/c5a9c5973bf735f1bb9d611cd50c796f6c32557e/src/Components/Web.JS/src/Platform/WebAssemblyConfigLoader.ts#L40