title: Unable to Accesss appsettings.json values in .NET Core 6 Web API
body: <p>I am migrating from .NET Core 5.0 to 6.0.</p>
  <p>The following piece of code works just fine in 6.0.</p>
  <pre><code>builder.Services.AddDbContext&lt;QuoteCMSContext&gt;(options =&gt;
          options.UseSqlite(&quot;Data Source=quotesdatabase.db&quot;));
  </code></pre>
  <p>Now, in my old 5.0 project, I had something like this.</p>
  <pre><code>    //database context
      services.AddDbContext&lt;QuoteCMSContext&gt;(options =&gt;
                  options.UseSqlite(Configuration[&quot;SqliteConnectionString&quot;]));
  </code></pre>
  <p>I looked at all these other questions, which appear to deal with my problem.</p>
  <p><a href="https://stackoverflow.com/questions/69722872/asp-net-core-6-how-to-access-configuration-during-startup">ASP.NET Core 6 how to access Configuration during startup</a></p>
  <p><a href="https://stackoverflow.com/questions/46940710/getting-value-from-appsettings-json-in-net-core">Getting value from appsettings.json in .net core</a></p>
  <p><a href="https://stackoverflow.com/questions/70631902/connectionstring-in-net-core-6">ConnectionString in .NET Core 6</a></p>
  <p>Eventually, I came up with this.</p>
  <pre><code>builder.Services.AddDbContext&lt;QuoteCMSContext&gt;(options =&gt;
          options.UseSqlite(builder.Configuration[&quot;SQLiteConnectionString&quot;]));
  </code></pre>
  <p>and this</p>
  <pre><code>builder.Services.AddDbContext&lt;QuoteCMSContext&gt;(options =&gt;
          options.UseSqlite(builder.Configuration.GetConnectionString(&quot;SQLiteConnectionString&quot;)));
  </code></pre>
  <p>in both cases, I keep getting null exceptions. I dont' know what I am missing.</p>
  <p>Here is my appsettings.json, just in case.</p>
  <pre><code>{
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;Default&quot;: &quot;Information&quot;,
        &quot;Microsoft.AspNetCore&quot;: &quot;Warning&quot;
      }
    },
    &quot;AllowedHosts&quot;: &quot;*&quot;,
    &quot;SQLiteConnectionString&quot;: &quot;Data Source=quotesdatabase.db&quot;,
    &quot;AzureSqlServerConnectionString&quot;: &quot;Server=tcp:.database.windows.net,1433;Initial Catalog=DBName;Persist Security Info=False;User ID=;Password=;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;&quot;,
    &quot;CorsOriginLocalHost&quot;: &quot;http://localhost:3000&quot;,
    &quot;CorsOriginStaging&quot;: &quot;https://randomstuffreactjsappzeropoint4.azurewebsites.net&quot;,
    &quot;CorsOriginProduction&quot;: &quot;https://randomstuffreactjsappzeropoint4.azurewebsites.net&quot;,
    &quot;ConnectionStrings&quot;: {
      &quot;SQLiteConnectionString&quot;: &quot;Data Source=quotesdatabase.db&quot;
    }
  }
  </code></pre>
  <p><strong>Update 1 :</strong></p>
  <p>I noticed something odd. The following code, does not raise any errors. Actually, sorry, I wasn't injecting cors in my code yet. This also gives the same null error. So, yes, at this point, definitely not able to read information from appsettings.json</p>
  <pre><code>builder.Services.AddCors(cors =&gt;
          {
              cors.AddDefaultPolicy( policy =&gt;
              {
                  policy.WithOrigins(builder.Configuration[&quot;CorsOriginLocalHost&quot;],
                                      builder.Configuration[&quot;CorsOriginStaging&quot;],
                                      builder.Configuration[&quot;CorsOriginProduction&quot;]);
      
      
                  //policy.WithOrigins(&quot;http://localhost:3000&quot;,
                  //                    &quot;http://localhost:3000&quot;
                  //                    );
                  policy.AllowAnyMethod();
                  policy.AllowAnyHeader();
                  policy.AllowCredentials();
              }
                  );
          }
      );
  </code></pre>
  <p><strong>Update 2 :</strong></p>
  <p>Okay, I found the problem. I had changed the 'Working Directory' while debugging SQLite. So, the code kept looking for appsettings.json in the wrong location. I set to the project folder manually. I used to do this step in .NET 5.0.</p>
  <p>Looks like it's not required in .NET 6.0</p>
  <p>I went back to project properties and removed the path I had set. made it blank. Now, able to read appsettings.json.</p>