-
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
Configuration data allows nullable values, but ChainedConfigurationProvider.TryGet doesn't work correctly with them #65594
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsSee the conversation here: dotnet/core#7211 (comment).
Line 66 in cf6dbde
This means that a ConfigurationProvider can have a However, ChainedConfigurationProvider doesn't seem to support this: runtime/src/libraries/Microsoft.Extensions.Configuration/src/ChainedConfigurationProvider.cs Lines 39 to 42 in cf6dbde
If the inner configuration returned This feels like an issue with our API design here. Can cc @maxkoshevoi @halter73 @HaoK
|
Found the reason of why |
I think the right behavior is for |
I just ran into this behavior of the We have a configuration system that get its values from a database, but all values can be overwritten per environment or secrets. Environment and secrets come from the ChainedConfigurationProvider, while the database values have their own I wanted to overwrite one value with I agree with @halter73 that |
Just adding a vote here. The current design results in a discrepancy between how Web Host and Generic Host read configuration data from appsettings.json files (presumably Generic Host uses ChainedConfigurationProvider). Web Host supports/returns empty strings verbatim as valid configuration values whereas Generic host interprets these as null. This breaks the Sentry SDK when using Generic Host (which allows you to set the URL of your sentry server to string.Empty to disable the SDK): Arguably the current behavioural inconsistencies are a bug then. |
See the conversation here: dotnet/core#7211 (comment).
IConfigurationProvider.TryGet(string key, out string? value);
is nullable annotated asruntime/src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.cs
Line 66 in cf6dbde
This means that a ConfigurationProvider can have a
null
value for a key. So it would returntrue
and thevalue == null
.However, ChainedConfigurationProvider doesn't seem to support this:
runtime/src/libraries/Microsoft.Extensions.Configuration/src/ChainedConfigurationProvider.cs
Lines 39 to 42 in cf6dbde
If the inner configuration returned
null
, ChainedConfigurationProvider would returnfalse
, even though the it is possible the inner configuration provider returnedtrue
andvalue == null
.This feels like an issue with our API design here. Can
null
be a valid configuration value or not? If it can, shouldChainedConfigurationProvider
respect it?cc @maxkoshevoi @halter73 @HaoK
The text was updated successfully, but these errors were encountered: