-
Notifications
You must be signed in to change notification settings - Fork 5k
Support Null configuration #116677
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
base: main
Are you sure you want to change the base?
Support Null configuration #116677
Conversation
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs
Show resolved
Hide resolved
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
The tests should be fixed now. |
@@ -61,7 +66,7 @@ public void GetListNullValues() | |||
var list = new List<string>(); | |||
config.GetSection("StringList").Bind(list); | |||
|
|||
Assert.Empty(list); | |||
Assert.Equal([ null, null, null, null ], list); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting behavior (mainly the old behavior was interesting), make sure we document that in the breaking change. I agree with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the configuration binding logic to better support null configuration values, adjust error messages, and refine generated code to improve consistency and behavior. Key changes include replacing direct value checks with TryGetConfigurationValue invocations throughout the binder code and tests, updating error message formats to include the configuration value, and modifying code-generation logic in the source generator.
Reviewed Changes
Copilot reviewed 20 out of 81 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/SourceGenerationTests/Baselines/net462/* | Updated generated baselines to use TryGetConfigurationValue for null checking and improved error message formatting. |
src/Microsoft.Extensions.Configuration.Binder.cs | Revised binding logic to consider HasNewValue and adjusted array handling when configuration values are empty. |
tests/Common/ConfigurationBinderTests*.cs | Modified tests to expect behavior for null and empty configuration values. |
gen/Emitter/* | Updated source generator helper methods and error message constants to match the new error format and binding behavior. |
csproj | Added a new project reference to support the updated binding functionality. |
Comments suppressed due to low confidence (1)
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/ExceptionMessages.cs:16
- Ensure that the updated error message format is documented in the code comments and associated documentation so that its three-parameter structure is clearly understood by other developers.
public const string FailedBinding = "Failed to convert configuration value '{0}' at '{1}' to type '{2}'.";
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please make sure to get some partner testing of this if we can. Maybe a trial update of aspire and/or extensions repos? Something that will test the real-world usage of configuration. As we discussed we don't believe it will break anyone since folks wouldn't have been using null
in configuration today.
The breaking change issue is created dotnet/docs#46890. |
Fixes #116700
Fixes #36510