Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jun 14, 2025

@tarekgh tarekgh changed the title [WIP} Support Null configuration [WIP] Support Null configuration Jun 14, 2025
@tarekgh tarekgh added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jun 14, 2025
@tarekgh tarekgh added this to the 10.0.0 milestone Jun 14, 2025
@tarekgh tarekgh marked this pull request as ready for review June 18, 2025 01:33
@tarekgh tarekgh removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jun 18, 2025
@tarekgh tarekgh changed the title [WIP] Support Null configuration Support Null configuration Jun 18, 2025
@tarekgh tarekgh added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Jun 18, 2025
Copy link
Contributor

dotnet-policy-service bot commented Jun 18, 2025

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@dotnet-policy-service dotnet-policy-service bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jun 18, 2025
@tarekgh
Copy link
Member Author

tarekgh commented Jun 18, 2025

I'll fix the other configiguration providers (INI, Xml, and CommandLine) failing tests next.

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);
Copy link
Member

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.

@ericstj ericstj requested a review from Copilot June 18, 2025 17:51
Copy link
Contributor

@Copilot Copilot AI left a 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}'.";

Copy link
Member

@ericstj ericstj left a 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.

@tarekgh
Copy link
Member Author

tarekgh commented Jun 18, 2025

The breaking change issue is created dotnet/docs#46890.

@tarekgh tarekgh removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Configuration breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Expose a new Configuration API to help in Null values binding Null configuration elements deserialized as empty strings
2 participants