-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
ConfigurationBinder.Bind on virtual array property duplicates elements #70150
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionMicrosoft.Extensions.Configuration.ConfigurationBinder.Bind sets virtual properties multiple times when overridden. This appends a duplicate array for each overridden instance of virtual array properties. This appears to come from ConfigurationBinder.GetAllProperties, it adds overridden properties to its returned list multiple times. Reproduction Stepspublic class C1
{
public virtual string[] Test { get; set; } = System.Array.Empty<string>();
}
public class C2 : C1
{
public override string[] Test { get => base.Test; set => base.Test = value; }
}
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>()
{
["Test:0"] = "1",
})
.Build();
var test = new C2();
configuration.Bind(test);
// test.Test has two elements with value of "1" Expected behaviorI would expect test.Test to have one element "1" Actual behaviortest.Test has two elements with value of "1" Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
FYI link to code: runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Lines 673 to 688 in eef6c7f
|
Description
Microsoft.Extensions.Configuration.ConfigurationBinder.Bind sets virtual properties multiple times when overridden. This appends a duplicate array for each overridden instance of virtual array properties.
This appears to come from ConfigurationBinder.GetAllProperties, it adds overridden properties to its returned list multiple times.
Reproduction Steps
Expected behavior
I would expect test.Test to have one element "1"
Actual behavior
test.Test has two elements with value of "1"
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: