Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading test.html using MapStaticAssets: Failed to load resource: net::ERR_CONTENT_DECODING_FAILED #58940

Open
danroth27 opened this issue Nov 14, 2024 · 19 comments
Labels
area-ui-rendering Includes: MVC Views/Pages, Razor Views/Pages External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-static-web-assets
Milestone

Comments

@danroth27
Copy link
Member

danroth27 commented Nov 14, 2024

Repro steps:

  • Create an empty ASP.NET Core app
  • Add app.MapStaticAssets()
  • Add wwwroot/test.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1>Test</h1>
</body>
</html>

Run the app and browser to /test.html

Expected result: test.html renders in the browser

Actual result: Failed to load resource: net::ERR_CONTENT_DECODING_FAILED

Workarounds:

  • Swap app.MapStaticAssets() for app.UseStaticFiles()
  • Use a .json file instead of a .html file
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 14, 2024
@fingers10
Copy link

fingers10 commented Nov 14, 2024

@danroth27 I'm facing same issue in blazor wasm standalone app. I upgraded my .net8 blazor wasm standalone app to .net9. The app has authentication setup using oauth and openidconnect. Entire blazor wasm is under authorisation. So when the index.html load usually it wil redirect to identity provider to challenge user. This was working in .net8. But after upgrading to .net9 and when I do dotnet watch run, I see the below blank page.

Image

Meanwhile in terminal,

Image

When I manually navigate to any URL in my blazor wasm app, it loads the page. But i can see the below error in console

Image

And if I click refresh button in browser, I again see the below blank page

Image

Now I need to press ctrl + c in terminal and that throws the following error

dotnet watch 🛑 Shutdown requested. Press Ctrl+C again to force exit.
dotnet watch ❌ System.FormatException: Input string was not in a correct format. Failure to parse near offset 115. Expected an ASCII digit.
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.Format(String format, Object[] args)
   at Microsoft.Extensions.Tools.Internal.MessageDescriptor.TryGetMessage(String prefix, Object[] args, String& message)
   at Microsoft.Extensions.Tools.Internal.ConsoleReporter.Report(MessageDescriptor descriptor, String prefix, Object[] args)
   at Microsoft.Extensions.Tools.Internal.IReporter.Report(MessageDescriptor descriptor, Object[] args)
   at Microsoft.Extensions.Tools.Internal.IReporter.Verbose(String message, String emoji)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.<>c__DisplayClass6_0.<<ReportSolutionFilesAsync>g__InspectDocumentAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.ReportSolutionFilesAsync(Solution solution, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.UpdateProjectConeAsync(String rootProjectPath, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred

Again I need to dotnet watch run and index.html will be blank with Failed to load resource: net::ERR_CONTENT_DECODING_FAILED error in console and i need manually navigate to any page by changing url in browser and if I try to log out I again see the below error. Calls getting cancelled in network tab.

Image

Now If I rollback to .net8 still the issue persist. net9 installation broke something.

I tested this in VS Code in Mac OS sequoia 15.1 and also in Visual Studio in windows 11. Facing same issue in both machines. Looks like local development is blocked because of this.

I notice this behavior only in development mode. I tried to publish and run in IIS and I dont see any issue.

@peterthorpe81
Copy link

I also have this issue, changing the file extension results in the wrong mime type sent to the browser so doesn't work for my use case.

A potential alternative workaround is creating a different static directory for your html files. Then use MapStaticAssets alongside:

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(builder.Environment.ContentRootPath, "Static")),
    RequestPath = "/Static"
});

I am assuming its valid to use both if UseStaticFiles is set to an alternative directory.

@space-alien
Copy link

This is a pain.

I have found that the presence of a <body> tag within the html file somehow breaks the serving of the file.

OK:

<!DOCTYPE HTML>

<html>

This file is seemingly served correctly.

</html>

Broken:

<!DOCTYPE HTML>

<html>

<body>
    This file won't render in the browser. Dev tools report "Failed to load
    response data: No data found for resource with given identifier".
    Yum.
</body>

</html>

Hope this helps.

@fingers10
Copy link

This is a pain.

I have found that the presence of a <body> tag within the html file somehow breaks the serving of the file.

OK:

This file is seemingly served correctly.

Broken: This file won't render in the browser. Dev tools report "Failed to load response data: No data found for resource with given identifier". Yum. Hope this helps.

by default blazor wasm apps will serve index.html file and is that why my blazor wasm apps are not getting served? @danroth27 any helps?

@danroth27
Copy link
Member Author

@javiercn

@Broderick890
Copy link

Same issue,How is it going?

@Pragmateek
Copy link

This bug is still crawling, I have the exact same scenario and symptoms as @danroth27.
With MapStaticAssets Kestrel's response add a Content-Encoding: gzip header.
With UseStaticFiles this header is not specified at all.

@javiercn
Copy link
Member

javiercn commented Feb 3, 2025

Setting "ReloadStaticAssetsAtRuntime": "false" should workaround the issue.

@SteveSandersonMS
Copy link
Member

@javiercn Will we be fixing this in a patch?

@danroth27 danroth27 added area-ui-rendering Includes: MVC Views/Pages, Razor Views/Pages and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Feb 5, 2025
@danroth27
Copy link
Member Author

This issue appears to only happen in VS with browser link enabled. We think the issue is due to how browser link intercepts the response and tries to inject content into it.

@MackinnonBuck MackinnonBuck added the External This is an issue in a component not contained in this repository. It is open for tracking purposes. label Feb 5, 2025
@MackinnonBuck MackinnonBuck added this to the 10.0-preview2 milestone Feb 5, 2025
@dashiell-zhang
Copy link

This issue appears to only happen in VS with browser link enabled. We think the issue is due to how browser link intercepts the response and tries to inject content into it.

@danroth27 Hello,This problem exists not only when Visual Studio is running. After the code is released and deployed in nginx, net::ERR_CONTENT_DECODING_FAILED will still appear when accessing the corresponding test.html from other computers.

@fingers10
Copy link

@danroth27 this issue happens when hot reload is enabled. I'm able to reproduce this in vs code .net 9 standalone blazor wasm app. But when I run without hot reload using --no-hot-reload this is not happening

@danroth27
Copy link
Member Author

@fingers10 Thanks for these additional details! That's probably because of a similar issue where hot reload is trying to inject a script on to the page.

@danroth27
Copy link
Member Author

@danroth27 Hello, This problem exists not only when Visual Studio is running. After the code is released and deployed in nginx, net::ERR_CONTENT_DECODING_FAILED will still appear when accessing the corresponding test.html from other computers.

@fingers10 Hmm, that is odd. Could this possibly be due to a misconfiguration of the compression settings in nginx?

@fingers10
Copy link

@fingers10 Thanks for these additional details! That's probably because of a similar issue where hot reload is trying to inject a script on to the page.

@danroth27 Any suggestion / workaround for this? its difficult without hot reload

@danroth27
Copy link
Member Author

danroth27 commented Feb 7, 2025

@danroth27 Any suggestion / workaround for this? its difficult without hot reload

@fingers10 See #58940 (comment)

@fingers10
Copy link

Setting "ReloadStaticAssetsAtRuntime": "false" should workaround the issue.

@danroth27 @javiercn I'm facing this issue with standalone blazor wasm app. Where should I add this setting in blazor wasm standalone app?

@Mohamed1984
Copy link

Mohamed1984 commented Feb 25, 2025

Setting "ReloadStaticAssetsAtRuntime": "false" should workaround the issue.

@danroth27 @javiercn I'm facing this issue with standalone blazor wasm app. Where should I add this setting in blazor wasm standalone app?

In lauchSettings.json

Anyway, it seems the issue is due to gzip compression of static assets collides with browser link. You can stop hot reload by adding the following line in launchSettings.json
"hotReloadEnabled": false

"https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "https://localhost:5032", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "hotReloadEnabled": false },

@fingers10
Copy link

@Mohamed1984 Many thanks for the support and help.

@danroth27 @javiercn , I'm surprised..

  1. I added "reloadStaticAssetsAtRuntime": "false" in launchSettings.json and did dotnet watch run
  2. Now I stopped the app and changed the value to "reloadStaticAssetsAtRuntime": "true" and did dotnet watch run
  3. Now I stopped the app and then removed "reloadStaticAssetsAtRuntime": "false" from launchSettings.json and did dotnet watch run

Now hot reload is working without any issues even if I don't have "reloadStaticAssetsAtRuntime": "false" in launchSettings.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ui-rendering Includes: MVC Views/Pages, Razor Views/Pages External This is an issue in a component not contained in this repository. It is open for tracking purposes. feature-static-web-assets
Projects
None yet
Development

No branches or pull requests