dotnet / dotnet/aspnetcore

WebApplicationBuilder throws DirectoryNotFoundException when wwwroot is empty but has links

Open
#49,859 2 comments 1 reaction 0 assignees View on GitHub
area-mvc bug
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

The issue occurs if the following happen:
* An Asp.Net Core hosted blazor application is used
* A razor class library is referenced by the client project
* The wwwroot project of the razor class library is empty except for `` items

Then the application throws `System.IO.DirectoryNotFoundException: 'C:\Git\Repro\Repro\RCL\wwwroot\'` at startup

### Expected Behavior

No exception should be thrown at startup

### Steps To Reproduce

https://github.com/TomGathercole/EmptyWwwrootRepro

### Exceptions (if any)

System.IO.DirectoryNotFoundException
HResult=0x80070003
Message=C:\Git\Repro\Repro\RCL\wwwroot\
Source=Microsoft.Extensions.FileProviders.Physical
StackTrace:
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.<>c.b__1_0(String contentRoot)
at Microsoft.AspNetCore.StaticWebAssets.ManifestStaticWebAssetFileProvider..ctor(StaticWebAssetManifest manifest, Func`2 fileProviderFactory)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssetsCore(IWebHostEnvironment environment, Stream manifest)
at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssets(IWebHostEnvironment environment, IConfiguration configuration)
at Microsoft.AspNetCore.Hosting.BootstrapHostBuilder.RunDefaultCallbacks()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder..ctor(WebApplicationOptions options, Action`1 configureDefaults)
at Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(String[] args)
at Repro.Program.Main(String[] args) in C:\Git\Repro\Repro\Server\Program.cs:line 9

### .NET Version

7.0.306

### Anything else?

It looks like `C:\Git\Repro\Repro.RCL\wwwroot\` is included under `ContentRoots` in the `Repro.RCL.staticwebassets.runtime.json` file, even if the file does not exist. I suppose that this path should not be included if it does not exist, or StaticWebAssetsLoader shouldn't throw if it is missing

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.