-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
ASP.NET configuration started to behave differently starting from 10.0.0-preview.6.25276.106 when performing a Configuration.Bind()
to the configuration model.
We observed a change on the benchmark-lab where builder.Configuration
was doing a binding to the in-app model representing settings, and without any related changes in aspnetcore repo, value started to being picked from appsettings instead of environment variable.
Basically:
// imagine we have appsettings with `ConnectionString: ....`
// and environment variable `ConnectionString: ...`
var builder = WebApplication.CreateBuilder(args);
var appSettings = new AppSettings();
builder.Configuration.Bind(appSettings);
Console.WriteLine(appSettings.ConnectionString); // gives value from appsettings
if you run such a repro on net9, it will take environment variable value.
The weird part is that builder.Configuration
contains env variable value, but appsettings is still binded.
Reproduction Steps
repro: https://github.com/DeagleGross/Baraholka/tree/main/BindingRepro
.net10 output:
.NET Runtime Version: .NET 10.0.0-preview.7.25358.104
.NET Runtime Identifier: win-x64
Process Architecture: X64
OS Architecture: X64
builder.Configuration["ConnectionString"]: environment variable value
AppSettings.ConnectionString: appsettings value
.net9 output:
.NET Runtime Version: .NET 9.0.7
.NET Runtime Identifier: win-x64
Process Architecture: X64
OS Architecture: X64
builder.Configuration["ConnectionString"]: environment variable value
AppSettings.ConnectionString: environment variable value
Expected behavior
Configuration should take value from environment variable
Actual behavior
Configuration takes value from appsettings
Regression?
working version: 10.0.0-preview.5.25265.101
version with regression: 10.0.0-preview.6.25276.106
Known Workarounds
No response
Configuration
No response
Other information
Looks like a regression from Support Null configuration (dotnet/runtime#116677) based on the dates.