title: .NET Core 3.1 Environment not correct
body: <p>I have a .NET Core 3.1 Web API I recently pushed to a dev Azure VM to run on IIS.  Upon deploying the API, I noticed the app wasn't starting up and I wasn't even getting a detailed IIS stack trace, just a plain 404 error.  So I checked the Windows Event Viewer and found the following:</p>
  <pre><code>System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
     at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
  </code></pre>
  <p>The connectionString key only existed in my appsettings.Development.json.  It dawned on me to add the connection string to my appsettings.json and the error went away.  But I wanted to use a different db connection string for my dev environment.  So I know what you all are thinking at this point, so I went ahead and checked/confirmed the environment variables on the server:</p>
  <p><a href="https://i.stack.imgur.com/c1dfm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1dfm.png" alt="env" /></a></p>
  <pre><code>C:\windows\system32&gt;reg query &quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
      ASPNETCORE_ENVIRONMENT    REG_SZ    Development
      ComSpec    REG_EXPAND_SZ    %SystemRoot%\system32\cmd.exe
  
  </code></pre>
  <p>So I went ahead and added the following to my Startup:</p>
  <pre><code>       public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger&lt;Startup&gt; logger)
          {
              var connstr = Configuration.GetConnectionString(&quot;MyDbContext&quot;);
  
              logger.LogInformation($&quot;ApplicationName: {env.ApplicationName}&quot;);
              logger.LogInformation($&quot;EnvironmentName: {env.EnvironmentName}&quot;);
              logger.LogInformation($&quot;ContentRootPath: {env.ContentRootPath}&quot;);
              logger.LogInformation($&quot;WebRootPath: {env.WebRootPath}&quot;);
              logger.LogInformation($&quot;DbConnection: {connstr}&quot;);
  </code></pre>
  <p>and checked my stdout logs:</p>
  <pre><code>info: MyProject.API.Startup[0]
        ApplicationName: MyProject.API
  info: MyProject.API.Startup[0]
        EnvironmentName: Production
  info: MyProject.API.Startup[0]
        ContentRootPath: C:\inetpub\wwwroot\myapi
  info: MyProject.API.Startup[0]
        WebRootPath: 
  info: MyProject.API.Startup[0]
        DbConnection: &lt;my connection string from appsettings.json&gt;
  </code></pre>
  <p>So I don't understand if this is some new .NET Core 3.1 change or why my API is not detecting the ASPNETCORE_ENVIRONMENT variable as Development.</p>