Tommy
Tommy copied to clipboard
Configuration binding of array leads to duplicate values
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.)