-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-Extensions-Configurationbughelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors
Milestone
Description
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
public 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 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
Metadata
Metadata
Assignees
Labels
area-Extensions-Configurationbughelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors