Skip to content

.NET 10 binding an IEnumerable record entries missing when nullable parameters are null #7210

@norr-carr

Description

@norr-carr

Description

We have Web Application with configuration supplied by an appsettings.json file. The configuration includes a collection of a custom type with nullable values. Prior to upgrading to .NET 10, the collection included instances with null entries in the nullable fields. After upgrading to .NET 10, any entry with a null field is missing from the collection.

Reproduction Steps

I created a basic Web Application in Visual Studio. The Program.cs includes:

var builder = WebApplication.CreateBuilder(args);

var options = builder.Configuration.GetSection("CustomOptions").Get<Options>();

builder.Services.AddControllers();

var app = builder.Build();

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

public record Options
{
  public string? EnableFeatureX { get; init; }
  public IEnumerable<User> Users { get; init; } = [];
}

public record User
(
  int Id,
 string? Name
);

and the appsettings file includes:

{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "CustomOptions": { "EnableFeatureX": null, "Users": [ { "Id": 1, "Name": "Noah" }, { "Id": 2, "Name": null } ] } }

Expected behavior

I expect to see that the "options" object when run has two entries in the Users ienumerable, one with Id: 1, Name: "Noah" and one with Id: 2, Name: null

Image

Actual behavior

The "options" object only has one entry, Id: 1, Name: "Noah"

Image

Regression?

This works as I expect in .NET 9. It does not work in .NET 10. I am aware of the breaking change to Null values in the configuration, however my understanding is that this should not have changed the behavior in my case. https://learn.microsoft.com/en-us/dotnet/core/compatibility/extensions/10.0/configuration-null-values-preserved

Known Workarounds

No response

Configuration

net10.0
Visual Studio 26 (18.2)
Windows 11

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-fundamentalsbugThis issue describes a behavior which is not expected - a bug.untriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions