The Wayback Machine - https://web.archive.org/web/20220115105227/https://github.com/dotnet/aspnetcore/issues/39546
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

Not possible to call WebHost.ConfigureAppConfiguration when a wwwroot directory exists #39546

Open
1 task done
aurecchia opened this issue Jan 15, 2022 · 0 comments
Open
1 task done

Comments

@aurecchia
Copy link

@aurecchia aurecchia commented Jan 15, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When a wwwroot directory exists, calling the WebHost.ConfigureAppConfiguration method throws a System.NotSupportedException error because of the web root having changed, despite that not happening in the user code.

Expected Behavior

I would expect to be able to call the WebHost.ConfigureAppConfiguration method without it throwing an exception when the web root is not changed in the configuration delegate.

Steps To Reproduce

To reproduce, simply run the project (dotnet run). The following program (plus a wwwroot directory) is enough to trigger it.

var builder = WebApplication.CreateBuilder(args);

// The configuration delegate, clearly, does not do anything
// Commenting out the call to `ConfigureAppConfiguration` "solves" the issue
builder.WebHost.ConfigureAppConfiguration(
    (ctx, config) => { });

var app = builder.Build();

app.MapGet("/", () => "hello!");

app.Run();

A project to reproduct the issue lives at https://github.com/aurecchia/aspnetcore-wwwroot-confusion

Exceptions (if any)

Unhandled exception. System.NotSupportedException: The web root changed from "/home/<username>/aspnetcore-wwwroot-confusion/wwwroot" to "/home/<username>/aspnetcore-wwwroot-confusion/". Changing the host configuration using WebApplicationBuilder.WebHost is not supported. Use WebApplication.CreateBuilder(WebApplicationOptions) instead.
   at Microsoft.AspNetCore.Builder.ConfigureWebHostBuilder.ConfigureAppConfiguration(Action`2 configureDelegate)
   at Program.<Main>$(String[] args) in /home/<username>/aspnetcore-wwwroot-confusion/Program.cs:line 3

.NET Version

6.0.100

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant