Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I represent a json array in an Environment Variable for aspnet vnext configuration

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?

like image 690
Paul Devenney Avatar asked Mar 11 '23 20:03

Paul Devenney


1 Answers

Try this:

Name Settings:IgnoredServices:0

Value ignore1

Name Settings:IgnoredServices:1

Value ignore2

like image 121
adem caglin Avatar answered Apr 12 '23 14:04

adem caglin