Question Details

No question body available.

Tags

c# .net-core configuration record .net-10.0

Answers (1)

January 21, 2026 Score: 0 Rep: 120,905 Quality: Medium Completeness: 100%

If you change Id and Name from record parameters to init-only properties then the .NET 9 behavior is restored and the list is deserialized with two entries:

public record User
{
    public int Id { get; init; }
    public string? Name { get; init; }
};

And, to test:

var options = builder.Configuration.GetSection("CustomOptions").Get();
Assert.That(options?.Users.Count() == 2); // PASSES

Notes -

  • I have no explanation as to why this is true. The problem seems specific to types with parameterized constructors. If I modify your User type as follows, changing it from a record to a class with a single parameterized constructor:

    public class User
    {
        public User(int id, string? name) => (this.Id, this.Name) = (id, name); 
        public int Id { get; }
        public string? Name { get; }
    }
    

    Then .NET 9 loads both users (demo here) but .NET 10 can only load one of the two users (demo here).

    This appears to be a bug or regression. You might want to open an issue with Microsoft.

  • The fact that the init-only record property Options.EnableFeatureX was deserialized successfully despite being null was the hint that led me to this workaround.

Demos:

  • Working .NET 9 demo here.
  • Failing .NET 10 demo using identical code here.
  • Fixed .NET 10 demo using the modified User type here.