Tommy icon indicating copy to clipboard operation
Tommy copied to clipboard

Configuration binding of array leads to duplicate values

Open ite-klass opened this issue 4 months ago • 0 comments

With configuration binding I see array values being duplicated.

With an app.toml file containing

[Logging]

[Logging.Sql]

[Logging.Email]
To = ['email1', 'email2']

config types

public record AppConfig(string ServiceName, LoggingConfig Logging)
{
    public AppConfig() : this(ServiceName: "AppName", Logging: new()) { }
}

public record LoggingConfig
{
    public LoggingEmailConfig? Email { get; set; }
}

public record LoggingEmailConfig(string[] To) { }

and setup

configurationManager.AddTomlFile("app.toml", optional: false, reloadOnChange: false);
var config = configurationManager..Get<AppConfig>();

config.Email.To now contains ["email1", "email2", "email1", "email2"] instead of ["email1", "email2"].

(I dropped unrelated properties and values from the types and toml to simplify the example.)

ite-klass avatar Apr 17 '24 11:04 ite-klass