dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.46k stars 10.03k forks source link

wwwroot DirectoryNotFound #51219

Closed oqo0 closed 11 months ago

oqo0 commented 1 year ago

Is there an existing issue for this?

Describe the bug

After enabling static file serving and adding wwwroot to the .NET 7 project and then removing them an unhandled exception is created. It's despite the fact that no middleware or dependencies use wwwroot. System.IO.DirectoryNotFoundException: project-path/wwwroot/

Expected Behavior

There should be no DirectoryNotFoundException.

Steps To Reproduce

1) Create new .NET ASP.NET WebAPI (default template) 2) Launch it to see if everything works. 3) Enable static file serving in Program.cs

app.UseStaticFiles();

Also add empty wwwroot to your project. 4) Build and start the project. 5) Remove static file serving and wwwroot from your project. Now we will get System.IO.DirectoryNotFoundException even thought there are no middleware or dependencies that use wwwroot.

Exceptions (if any)

System.IO.DirectoryNotFoundException

.NET Version

7.0.111

Anything else?

dotnet --info .NET SDK: Version: 7.0.111 Commit: 06c8b346e4

Runtime Environment: OS Name: fedora OS Version: 38 OS Platform: Linux RID: fedora.38-x64 Base Path: /usr/lib64/dotnet/sdk/7.0.111/

Host: Version: 7.0.11 Architecture: x64 Commit: ecb34f85ec

.NET SDKs installed: 6.0.122 [/usr/lib64/dotnet/sdk] 7.0.111 [/usr/lib64/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.22 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.11 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.22 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.11 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: DOTNET_ROOT [/usr/lib64/dotnet]

global.json file: Not found

javiercn commented 1 year ago

@oqo0 thanks for contacting us.

Does the error go away if you rebuild the project?

oqo0 commented 1 year ago

@javiercn No, rebuilding doesn't help.

mkArtakMSFT commented 1 year ago

Could you also try to remove the bin and obj folders and see if the behavior perists?

If yes, then we will need a repro to investigate this further.

ghost commented 1 year ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

oqo0 commented 1 year ago

Could you also try to remove the bin and obj folders and see if the behavior perists?

@mkArtakMSFT Deleting obj fixed the issue. Thank you. Still I'm not sure if this is a behaviour people would expect. When I removed UseStaticFiles and wwwroot it took me a while to realize that it's not an issue with my project.

javiercn commented 1 year ago

@oqo0 thanks for the details. This is very likely and edge case issue with incrementalism on the build.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.