-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When serializing options, I expect an empty JSON-object { } to be serialized to an empty Dictionary.
Expected Behavior
When reading an options-object using configuration.GetSection("Foo").Get<FooOptions>(); I expect a dictionary to be empty not null.
Steps To Reproduce
- Create a configuration
{
"Foo" : {
"Bar": 1,
"Baz": {
}
}
}- Create an OPTIONS object
public record FooOptions
{
public required int Bar { get; init; }
public required IDictionary<string, string> Baz{ get; init; }
}- Read it!
public void ConfigureServices(IConfiguration configuration, IServiceCollection services, TokenCredential credential)
{
var fooOptions = configuration.GetSection("Foo").Get<FooOptions>();
foreach ((var key, var value) in Baz) {
// do something
}
}Expected behavior:
fooOptions.Baz is an empty dictionary, which can be enumerated
Actual behavior:
fooOptions.Baz is null
Exceptions (if any)
No response
.NET Version
8.0.301
Anything else?
This behavior occurs in a ASP.NET 8 project