-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
IConfiguration binding behave unexpectedly when binding empty strings from nested configurations #62532
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescribe the bugBinding configuration with empty string as value ("") will result in To Reproduce
Further technical details
dotnet --info Output
|
Here's a simpler repro: test.json{
"NullIfChained": ""
} Program.csvar config1 = new ConfigurationBuilder().AddJsonFile("test.json").Build();
var config2 = new ConfigurationBuilder().AddConfiguration(config1).Build();
Console.WriteLine($"config1[\"NullIfChained\"] = \"{config1["NullIfChained"] ?? "(null)"}\"");
Console.WriteLine($"config2[\"NullIfChained\"] = \"{config2["NullIfChained"] ?? "(null)"}\""); Output
This appears to be caused by this logic in ChainedConfigurationProvider: runtime/src/libraries/Microsoft.Extensions.Configuration/src/ChainedConfigurationProvider.cs Lines 39 to 43 in a1bc0f3
Most ConfigurationProviders will just look for the presence of a string in the runtime/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationProvider.cs Lines 38 to 39 in a1bc0f3
ChainedConfigurationProvider doesn't have access to a dictionary, just the nested |
See also #65594 |
If we decided it is an OK breaking change, it would make sense to fix as long as the behavior between Configuration and ConfigurationManager stays consistent. |
Describe the bug
Binding configuration with empty string as value ("") will result in
null
if the section it binds to comes from a nested configuration.To Reproduce
Further technical details
dotnet --info
:dotnet --info Output
The text was updated successfully, but these errors were encountered: