Description
Reading JSON configuration file (appsettings.json) and binding it to a class with default constructor containing params keyword using ConfigurationBinder.Get<T> results in a duplicate list items.
Reproduction Steps
- Create a class with default constructor containing params keyword and a getter only List field that has the value from default constructor assigned
- Create a section in appsettings.json
- Bind that section to the class
- The resulting list has a duplicated item
Example that triggers the bug
public sealed record ErpConfigurationOptions(
NexoConfiguration? NexoConfiguration = null,
BlackBaseConfiguration? BlackBaseConfiguration = null)
{
public const string SectionName = "ErpConfiguration";
}
public class BlackBaseConfiguration(params List<BlackBaseInstance> instances)
{
public List<BlackBaseInstance> Instances { get; } = instances;
}
public record BlackBaseInstance(int Id, string InstanceName, char Symbol, string DbfDirectory);
var erpConfig = configuration.GetSection(ErpConfigurationOptions.SectionName)
.Get<ErpConfigurationOptions>() ?? throw new InvalidOperationException("ERP configuration is missing.");
{
"ErpConfiguration": {
"NexoConfiguration": {
"SqlConnectionString": ""
},
"BlackBaseConfiguration": {
"Instances": [
{
"Id": 1,
"InstanceName": "Poznan",
"Symbol": "P",
"DbfDirectory": "/mnt/dbf"
}
]
}
}
}
Expected behavior
No duplicate should occur.
Actual behavior
A duplicated list item is read from JSON config which only contains one list item.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
Microsoft.Extensions.Configuration v10.0.9
Description
Reading JSON configuration file (appsettings.json) and binding it to a class with default constructor containing params keyword using
ConfigurationBinder.Get<T>results in a duplicate list items.Reproduction Steps
Example that triggers the bug
{ "ErpConfiguration": { "NexoConfiguration": { "SqlConnectionString": "" }, "BlackBaseConfiguration": { "Instances": [ { "Id": 1, "InstanceName": "Poznan", "Symbol": "P", "DbfDirectory": "/mnt/dbf" } ] } } }Expected behavior
No duplicate should occur.
Actual behavior
A duplicated list item is read from JSON config which only contains one list item.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
Microsoft.Extensions.Configuration v10.0.9