Skip to content

Duplicate List<T> items when binding class with default constructor containing params keyword to IConfiguration #129760

Closed

Description

@DawidBartniczak

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

  1. Create a class with default constructor containing params keyword and a getter only List field that has the value from default constructor assigned
  2. Create a section in appsettings.json
  3. Bind that section to the class
  4. 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"
        }
      ]
    }
  }
}
Screenshot

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

Activity

  1. added
    untriaged
    on Jun 23, 2026
  2. dotnet-policy-service commented on Jun 23, 2026

    @dotnet-policy-service
    Contributor

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

  3. MihuBot commented on Jun 23, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. removed
    untriaged
    on Jun 23, 2026
  5. added this to the 11.0.0 milestone on Jun 23, 2026
  6. tarekgh commented on Jun 23, 2026

    @tarekgh
    Member

    Thanks for reporting this.

    The root cause is in the reflection based configuration binder. When a type is created through a constructor and the constructor parameter name differs only by case from a collection property (for example a parameter instances and a property Instances), the binder bound the property a second time in addition to the constructor, which appended the items again and produced the duplicates. The rest of the binder matches constructor parameters and properties case-insensitively, so this was an inconsistency in one comparison.

    Plan:

  7. added a commit that references this issue on Jun 26, 2026
    4d1dc2a
  8. added a commit that references this issue on Jul 15, 2026
    7e0c03c
  9. locked and limited conversation to collaborators on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions