ConfigurationBinder Source Generator doesn't call setters in same way reflection based ConfigurationBinder does #96873
Labels
area-Extensions-Configuration
in-pr
There is an active PR which will close this issue when it is merged
Priority:1
Work that is critical for the release, but we could probably ship without
source-generator
Indicates an issue with a source generator feature
Milestone
Description
When a configuration doesn't contain anything for a collection property (in the below case the
ResponseHeadersDataClasses
collection), the ConfigurationBinder reflection based implementation will still call the setter for the collection. But switching to the ConfigurationBinder source generator causes the setter to no longer be invoked.Reproduction Steps
csproj:
appsettings.json:
Program.cs:
Toggle the
EnableConfigurationBindingGenerator
setting betweentrue
andfalse
.Expected behavior
The behavior of the app should be the same whether you are setting
EnableConfigurationBindingGenerator
to false or true. It should printResponseHeadersDataClasses setter called!
in both cases.Actual behavior
When the Source Generator is not used:
When the Source Generator is used:
Other information
See this comment (and #80438) why the setter is being called in the non-SG case.
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Lines 276 to 281 in e458d68
In the source generator case, the generated code looks like:
So the setter is only ever called when a
ResponseHeadersDataClasses
section with children is present in the configuration.The text was updated successfully, but these errors were encountered: