Skip to content

WebApplicationBuilder throws DirectoryNotFoundException when wwwroot is empty but has links #49859

Open
@TomGathercole

Description

@TomGathercole

Is there an existing issue for this?

  • 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 <Content ... Link=wwwroot...> 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, Func2 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, Action1 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions