Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
asp.net core ioptions with a list

I'm trying to read a list of values from the appsettings.json file. I'm able to read the Logging values with no problem, but the list values (i.e Servers) are null:

appsettings.json:

{
 "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
           "Default": "Debug",
           "System": "Information",
           "Microsoft": "Information"
      }
 },
 "Servers": [
      "SCHVW2K12R2-DB",
      "SCHVW2K12R2-DB\\MSSQL2016",
      "SCHVW2K8R2-DB"
    ]
}

Object Classes:

public class AppSettingsConfiguration
{
    public Logging Logging { get; set; }
    public Servers Servers { get; set; }
}

//Logging Objects
public class Logging
{
    public bool IncludeScopes { get; set; }
    public LogLevel LogLevel { get; set; }
}
public class LogLevel
{
    public string Default { get; set; }
    public string System { get; set; }
    public string Microsoft { get; set; }
}

//Server Objects
public class Servers
{
    public List<string> Names { get; set; }
}
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try deleting the Servers class and changing AppSettingsConfiguration to:

public class AppSettingsConfiguration
{
    public Logging Logging { get; set; }
    public string[] Servers { get; set; }
}

Servers is a simple string array, not a complex type.

about 4 years ago · Santiago Trujillo Report

0

To use your original classes, you can change your json to this. IMO, this is more readable.

{
     "Logging": {
          "IncludeScopes": false,
          "LogLevel": {
               "Default": "Debug",
               "System": "Information",
               "Microsoft": "Information"
          }
     },
     "Servers": {
        "Names": [
          "SCHVW2K12R2-DB",
          "SCHVW2K12R2-DB\\MSSQL2016",
          "SCHVW2K8R2-DB"
        ]
     }
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!