Skip to content

WebApplication does not react to appsettings.json changes #37046

@halter73

Description

@halter73

Describe the bug

Starting in rc2, WebApplicationBuilder indirectly disposes IConfigurationProviders that are still in use by WebApplication. For FileConfigurationProviders, this prevents IConfigurationProvider.GetReloadToken() from firing. This means changes to configuration sources like appsettings.json are not observed after the WebApplication is built.

To Reproduce

Run the following commands:

> dotnet new globaljson --sdk-version 6.0.100-rc.2.21472.38
> dotnew new web
> dotnet run

While the application is running, change "Microsoft.AspNetCore": "Warning" to "Microsoft.AspNetCore": "Information" and make a request.

Expected output:

C:\dev\halter73\MinimalPlayground master ≢  ~1 ❯ dotnet run
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7159
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5016
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\dev\halter73\MinimalPlayground
dbug: Microsoft.AspNetCore.Server.Kestrel[0]
      Config reload token fired. Checking for changes...
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39]
      Connection id "0HMC22SP3DB29" accepted.
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1]
      Connection id "0HMC22SP3DB29" started.
dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[3]
      Connection 0HMC22SP3DB29 established using the following protocol: Tls12
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 GET https://localhost:7159/ - -
...

Actual output:

> dotnet run
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7159
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5016
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\dev\halter73\MinimalPlayground

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-minimal-hostingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions