title: ASP.NET Core web service does not load appsettings.json into configuration
body: <p>I have an ASP.NET Core 2.1 Web Application with Razor Pages which has AAD authentication information defined in the <code>appsettings.json</code> file (courtesy of the default application template - see below on how I got there). However, when trying to configure the authentication in <code>Startup.cs</code> the configuration does not have any of the config values from my <code>appsettings.json</code>. If I inspect the <code>IConfiguration</code> object in the debugger then it appears to only have the environment variable configurations:</p>
  
  <p><a href="https://i.stack.imgur.com/orFrK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/orFrK.png" alt="enter image description here"></a></p>
  
  <p>Here's the <code>Startup.ConfigureServices</code> method where the issue lies:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
      {
          // This lambda determines whether user consent for non-essential cookies is needed for a given request.
          options.CheckConsentNeeded = context =&gt; true;
          options.MinimumSameSitePolicy = SameSiteMode.None;
      });
  
      services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
          .AddAzureAD(options =&gt;
          {
              // This is from the default template. It should work, but the relevant settings aren't there so options isn't populated.
              this.Configuration.Bind("AzureAd", options);
  
              // This of course works fine
              options.Instance = "MyInstance";
              options.Domain = "MyDomain";
              options.TenantId = "MyTenantId";
              options.ClientId = "MyClientId";
              options.CallbackPath = "MyCallbackPath";
          });
  
      services.AddMvc(options =&gt;
      {
          var policy = new AuthorizationPolicyBuilder()
              .RequireAuthenticatedUser()
              .Build();
          options.Filters.Add(new AuthorizeFilter(policy));
      })
      .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  }
  </code></pre>
  
  <p>And the service configuration in case it's important (note that this is being built on top of a service fabric stateless service):</p>
  
  <pre><code>protected override IEnumerable&lt;ServiceInstanceListener&gt; CreateServiceInstanceListeners()
  {
      return new ServiceInstanceListener[]
      {
          new ServiceInstanceListener(serviceContext =&gt;
              new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =&gt;
              {
                  ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
  
                  return new WebHostBuilder()
                              .UseKestrel(opt =&gt;
                              {
                                  int port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
                                  opt.Listen(IPAddress.IPv6Any, port, listenOptions =&gt;
                                  {
                                      listenOptions.UseHttps(GetCertificateFromStore());
                                      listenOptions.NoDelay = true;
                                  });
                              })
                              .ConfigureServices(
                                  services =&gt; services
                                      .AddSingleton&lt;StatelessServiceContext&gt;(serviceContext))
                              .UseContentRoot(Directory.GetCurrentDirectory())
                              .UseStartup&lt;Startup&gt;()
                              .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                              .UseUrls(url)
                              .Build();
              }))
      };
  }
  </code></pre>
  
  <p>To create this service, I used the wizard in VS2017. I selected an existing service fabric project (<code>.sfproj</code>) and chose <code>Services &gt; Add &gt; New Service Fabric Service</code> and chose <code>Stateless ASP.NET Core [for .NET Framework]</code>, then on the next page I chose <code>Web Application</code> (the one with Razor Pages, not MVC) and clicked <code>Change Authentication</code> where I chose <code>Work or School Accounts</code> and entered my AAD info. The only changes I have made to this template were adding the code inside the call to <code>AddAzureAD</code> in <code>Startup.ConfigureServices</code> and setting the <code>appsettings.json</code> files to always be copied to the output directory.</p>
  
  <p><strong>Why doesn't the <code>appsettings.json</code> file get loaded into the configuration?</strong> As I understand, this is supposed to happen by default, but something seems to be missing...</p>