Skip to content

Conversation

@tarekgh
Copy link
Member

@tarekgh tarekgh commented Nov 5, 2025

Fixes #118630

The configuration source generator can produce code that references collection types such as HashSet without including the System.Collections.Generic namespace. This results in a compilation error. More users have started encountering this issue when using project templates like webapiaot and disabling ImplicitUsings.

Copilot AI review requested due to automatic review settings November 5, 2025 01:33
@tarekgh tarekgh added this to the 11.0.0 milestone Nov 5, 2025
@tarekgh tarekgh added the source-generator Indicates an issue with a source generator feature label Nov 5, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

@tarekgh
Copy link
Member Author

tarekgh commented Nov 5, 2025

CC @ezhevita

@tarekgh
Copy link
Member Author

tarekgh commented Nov 5, 2025

CC @jeffhandley @ericstj

Copy link
Contributor

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 moves the System.Collections.Generic namespace import to the initial namespace set in the binding helper code generator, removing conditional logic that previously added it only when processing object types.

  • Adds System.Collections.Generic to the default namespace set initialized in BindingHelperInfo.Builder
  • Removes the conditional namespace addition that occurred when registering object types
  • Updates all baseline test files to reflect the new namespace being consistently included
  • Adds a new test case for binding to collection-only scenarios

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

File Description
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/BindingHelperInfo.cs Moves System.Collections.Generic to the initial namespace set and removes conditional addition logic
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.cs Adds new test for binding to collection types only
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/*.generated.txt Updates baseline files to include the new namespace
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/*.generated.txt Updates baseline files to include the new namespace

@jeffhandley
Copy link
Member

/ba-g Timeouts in Android and known test failures

@jeffhandley
Copy link
Member

@tarekgh Since customers are reporting this against .NET 10 RC bits and the scenario is becoming more common, I would support submitting for servicing consideration, illustrating the webapiaot scenario, the code that triggers the error, and the workaround that you prescribed in the issue. The risk for the fix looks low.

@tarekgh
Copy link
Member Author

tarekgh commented Nov 6, 2025

/ba-g the failures are known timeout issues.

@tarekgh tarekgh merged commit 3a59507 into dotnet:main Nov 6, 2025
73 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Extensions-Configuration source-generator Indicates an issue with a source generator feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The configuration binder source generator fails to add the correct namespace when dealing with a dictionary root type

4 participants