title: ArgumentNullException for ConnectionString When trying to remotely connect to .net core API
body: <p>First of all is this happening in a Mac and I'm new to dotnet core.</p>
  
  <p>I have installed dockers and setup everything in dotnet core. I did add connectionstring to the 'appsettings' and 'appsettings(Development)'.</p>
  
  <pre><code>"ConnectionStrings": {
      "Default": "server=localhost; database=Monitor; User ID=sa; Password=MyComplexpPassword!234;"
    },
  </code></pre>
  
  <p>This is Program.cs file Main method</p>
  
  <pre><code> public static void Main(string[] args)
   {
        CreateWebHostBuilder(args).Build().Run();
   }
  </code></pre>
  
  <p>This is startup.cs class ConfigureServices method.</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
        services.AddAutoMapper();
  
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  
        services.AddDbContext&lt;MonitorDbContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("Default")));
  
              // In production, the Angular files will be served from this directory
        services.AddSpaStaticFiles(configuration =&gt;
        {
             configuration.RootPath = "ClientApp/dist";
        });
  
        services.AddScoped&lt;IUserRepository,UserRepository&gt;();
   }
  </code></pre>
  
  <p>This is a Controller test method to test API.</p>
  
  <pre><code>[HttpGet("getUser")]
  public UserResource GetUserInfo()
  {
         var user_1 = new User();
  
         user_1.FirstName = "MAC";
         user_1.LastName = "OS TEST";
         user_1.Username = "Apple@gmail.com";
  
  
         return mapper.Map&lt;User, UserResource&gt;(user_1);
  }
  </code></pre>
  
  <p>This method will perfectly execute If I make a rest call(http) without setting up Program.cs class for remote access.</p>
  
  <p><a href="https://i.stack.imgur.com/YsB2x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YsB2x.png" alt="enter image description here"></a></p>
  
  <p>Now I have set it up to run in '<a href="http://0.0.0.0:6001" rel="nofollow noreferrer">http://0.0.0.0:6001</a>', So that I can access the API from my phone or from another pc in the same wifi.
  I followed <a href="https://weblog.west-wind.com/posts/2016/Sep/28/External-Network-Access-to-Kestrel-and-IIS-Express-in-ASPNET-Core" rel="nofollow noreferrer">This instructions</a>.</p>
  
  <p>Now My Program.cs main method is like this.</p>
  
  <pre><code>public static void Main(string[] args)
  {
         // CreateWebHostBuilder(args).Build().Run();
  
         var configuration = new ConfigurationBuilder()
                  .AddCommandLine(args)
                  .Build();
  
  
         var hostUrl = configuration["hosturl"];
              if (string.IsNullOrEmpty(hostUrl))
                  hostUrl = "http://0.0.0.0:6000";
  
  
         var host = new WebHostBuilder()
                  .UseKestrel()
                  .UseUrls(hostUrl)   // &lt;!-- this 
                  .UseContentRoot(Directory.GetCurrentDirectory())
                  .UseIISIntegration()
                  .UseStartup&lt;Startup&gt;()
                  .UseConfiguration(configuration)
                  .Build();
  
              host.Run();
  
  }
  </code></pre>
  
  <p>In terminal I ran this command <code>dotnet run --hosturl http://0.0.0.0:6001</code> </p>
  
  <p>If try to access same method as before this happens.
  <a href="https://i.stack.imgur.com/Mt3LI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mt3LI.png" alt="enter image description here"></a> </p>
  
  <p>Notice:- I changed only the host, Because I need to test the API with other devices.</p>
  
  <p>I have other controllers and methods that are connecting to the database and do crud operations with it, Those API calls also face the same issue like this. This only happens if I set it up to remote access.</p>
  
  <p>Notice:- If I change the Startup.cs class Connection string line like this, It will work flawlessly in both configurations.</p>
  
  <pre><code>services.AddDbContext&lt;MonitorDbContext&gt;(options =&gt; options.UseSqlServer("server=localhost; database=Monitor; User ID=sa; Password=MyComplexpPassword!234;"));
  </code></pre>
  
  <p>But I felt that this is not good practice. In future, I have to add JWT Authentication to the API so that APP_Secret also needed to add to the AppSettings.json file.</p>
  
  <p>Thank you.</p>