dotnet / dotnet/aspnetcore

MapStaticAssets doesn't work with WebApplication.CreateSlimBuilder

Open
#58,986 7 comments 2 reactions 0 assignees View on GitHub
area-ui-rendering feature-static-web-assets
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Describe the bug

In an app built with `WebApplication.CreateSlimBuilder()` and using the new `MapStaticAssets` in .NET 9, responses for static files are empty with 200 status code. To reproduce, create a new ASPNET Core project from template, then change `WebApplication.CreateBuilder()` to `WebApplication.CreateSlimBuilder()` in Program.cs.

It appears that calling `UseStaticWebAssets` allows this to work, but this isn't documented as far as I can tell.

```
// Program.cs
var builder = WebApplication.CreateSlimBuilder(args);
builder.WebHost.UseStaticWebAssets();
var app = builder.Build();
...
app.MapStaticAssets();
```

Would like to understand what is expected and what the correct setup should be. It seems that if `CreateSlimBuilder` alone isn't sufficient, there should be some kind of warning visible to developer. At the very least, this aspect should be documented.

### Expected Behavior

Either `MapStaticAssets` truly works as a "drop-in replacelement" of `UseWebStaticFiles`, or incompatbilities are documented and/or warned to developer in tooling/build.

### .NET Version

9.0.100

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.