Skip to content

Microsoft.Extensions.Configuration: IReadOnlyList Options with default value are not filled #38852

@drauch

Description

@drauch

LABEL=area-Extensions-Configuration

Description

When I configure the following Options class:

class MyOptions
{
    // Null if not in appsettings.json, otherwise values from appsettings.json
    public string[] Works1 { get; set; }
    // Null if not in appsettings.json, otherwise values from appsettings.json
    public List<string> Works2 { get; set; }
    // Null if not in appsettings.json, otherwise values from appsettings.json
    public IReadOnlyList<string> Works3 { get; set; }
    // Empty if not in appsettings.json, otherwise values from appsettings.json
    public List<string> Works4 { get; set; } = new List<string>();
    // Empty in any case
    public IReadOnlyList<string> DOES_NOT_WORK { get; set; } = new List<string>();
}

The DOES_NOT_WORK is not properly filled, it is always empty, even if there are values in the appsettings.json

Configuration

.NET Framework 4.8 / Windows 10 / x64 / ASP.NET Core 2.1
(aspnetcore repo says that the Configuration package is now maintained here, which is why I'm filing the issue here, hope it's correct)

Best regards,
D.R.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions