4

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?

1
  • I'm also trying to store a JSON settings section in an Environment Variable. From what it seems, we can't. We have to individually create standalone variable for each settings and then pull those individually which yes is pretty clunky to me as well. Commented Sep 18, 2018 at 20:12

1 Answer 1

7

Try this:

Name Settings:IgnoredServices:0

Value ignore1

Name Settings:IgnoredServices:1

Value ignore2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.