-
Notifications
You must be signed in to change notification settings - Fork 850
Description
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
Actual behavior
The "options" object only has one entry, Id: 1, Name: "Noah"
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