title: How to load a child object in appsetting.json (asp.net core)
body: <p>I'm writing a little Action Filter for an ASP.NET Core web API project.  The filter is for testing the associated UI for error handling.  It will throw an error if a specific verb and method is invoked.  The filter isn't a problem.  The problem is the appsettings.configuration.</p>
  
  <p>Here's what I'm trying to do:
  appsettings.development.json</p>
  
  <pre><code>"FaultTesting": {
      "FaultRequests": false,
      "SlowRequests": 0,
      "FaultCalls": [
        {
          "Path": "/api/usercontext",
          "Verbs": "get,put,delete"
        },
        {
          "Path": "/api/cafeteriaaccounts",
          "Verbs": "get"
        }
      ]
    }
  </code></pre>
  
  <p>These are my c# types to hold the configuration:</p>
  
  <pre><code> public class FaultTestingOptions
      {
          /// &lt;summary&gt;
          /// If true, checks FaultCalls for a path and verb to match.
          /// &lt;/summary&gt;
          public bool FaultRequests { get; set; }
  
          /// &lt;summary&gt;
          /// Number of milliseconds to delay the response.
          /// &lt;/summary&gt;
          public int SlowRequests { get; set; }
  
          public FaultCall[] FaultCalls { get; set; }
  
      }
      public class FaultCall
      {
          public string Path { get; set; }
  
          public string Verbs { get; set; }
      }
  </code></pre>
  
  <p>Add what I'm doing in startup:</p>
  
  <pre><code>            services.AddMvc(config =&gt;
                  {
  ...
  FaultTestingFilter(Options.Create(GetFaultTestingOptions())));
  ...
                  });
  
  private FaultTestingOptions GetFaultTestingOptions()
  {
      var options = new FaultTestingOptions
      {
          FaultRequests = Configuration["FaultTesting:FaultRequests"].ToBoolean(),
          SlowRequests = Convert.ToInt32(Configuration["FaultTesting:SlowRequests"])
      };
  
      var calls = Configuration.GetSection("FaultTesting:FaultCalls")
          .GetChildren()
          .Select(x =&gt; x.Value)
          .ToArray();
  
      var fooie = Configuration["FaultTesting:FaultCalls"];
  
  
      //options.FaultCalls = calls.Select(c =&gt; new FaultCall { Path = c, Verbs = c.Value });
  
      return options;
  }
  </code></pre>
  
  <p>"calls" is an array of two nulls, fooie is null.</p>
  
  <p>What's the right approach here?</p>