I have the following section in my appsettings.json
file for my aspnet vnext application.
"Settings": {
"IgnoredServices" : ["ignore1", "ignore2"]
}
}
This works quite happily in mapping using IOptions<Settings>
, where the settings class is
public class Settings
{
public List<string> IgnoredServices { get; set; }
}
However, I am struggling to override this json file option with an environment variable form. I have tried
Name Settings:IgnoredServices
Value "ignore1", "ignore2"
and
Name Settings:IgnoredServices
Value ["ignore1", "ignore2"]
Neither seem to map correctly and I get the following error message
System.InvalidOperationException: Failed to convert '["ignore1", "ignore2"]'
to type 'System.Collections.Generic.List`1[System.String]
What format should I put my values into environment variables to be successfully interpreted as the correct list of strings?
Try this:
Name Settings:IgnoredServices:0
Value ignore1
Name Settings:IgnoredServices:1
Value ignore2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With