-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
ConfigurationBinder Source Generator is comparing configuration keys case-sensitively #88112
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionThe ConfigurationBinder Source Generator is generating code like this: foreach (IConfigurationSection section in configuration.GetChildren())
{
switch (section.Key)
{
case "ConnectionString":
{
obj.ConnectionString = configuration["ConnectionString"]!;
}
break;
case "JwtSigningKey":
{
obj.JwtSigningKey = configuration["JwtSigningKey"]!;
}
break; This is not correct because it is comparing the section's Key with "ConnectionString" in a case sensitive manner. However, configuration keys are case-insensitive. This causes setting environment variables like You can see this happening in the debugger below: Reproduction StepsWrite an app with an options class like: internal class AppSettings
{
public required string ConnectionString { get; set; }
public string? JwtSigningKey { get; set; }
public bool SuppressDbInitialization { get; set; }
} During app startup, bind the AppSettings to the configuration like (ensure you are using public static IServiceCollection ConfigureAppSettings(this IServiceCollection services, IConfigurationRoot configurationRoot, IHostEnvironment hostEnvironment)
{
services.AddSingleton<IValidateOptions<AppSettings>, AppSettingsValidator>()
.AddOptions<AppSettings>()
.BindConfiguration(nameof(AppSettings))
.ValidateOnStart(); Run the app with an environment variable set: Expected behaviorThe environment variable configuration should bind successfully. The AppSettings object should get its ConnectionString property set to the above. Actual behaviorThe environment variable fails to bind correctly. The ConnectionString property is left empty. Regression?This is a regression from the reflection based ConfigurationBinder. Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Description
The ConfigurationBinder Source Generator is generating code like this:
This is not correct because it is comparing the section's Key with "ConnectionString" in a case sensitive manner. However, configuration keys are case-insensitive. This causes setting environment variables like
APPSETTINGS__CONNECTIONSTRING
to no longer bind correctly.You can see this happening in the debugger below:
Reproduction Steps
Write an app with an options class like:
During app startup, bind the AppSettings to the configuration like (ensure you are using
EnableConfigurationBindingGenerator=true
):Run the app with an environment variable set:
$env:APPSETTINGS__CONNECTIONSTRING="Server=127.0.01;User Id=benchmarkdbuser;Password=benchmarkdbpass;Database=postgres"
.Expected behavior
The environment variable configuration should bind successfully. The AppSettings object should get its ConnectionString property set to the above.
Actual behavior
The environment variable fails to bind correctly. The ConnectionString property is left empty.
Regression?
This is a regression from the reflection based ConfigurationBinder.
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: