title: asp.net core 2.0 - Value cannot be null. Parameter name: connectionString
body: <p>I had the following error in package manager console when Add-Migration</p>
  
  <blockquote>
    <p>Value cannot be null.   Parameter name: connectionString</p>
  </blockquote>
  
  <p>This is my startup:</p>
  
  <pre><code>namespace MyProject
  {
      public class Startup
      {
          public IConfiguration Configuration { get; set; }
          public Startup(IConfiguration config)
          {
              Configuration = config;
          }
  
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContextPool&lt;AppDbContext&gt;(options =&gt;
                               options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
              services.AddTransient&lt;IDevRepo, DevRepo&gt;();
              services.AddMvc();
              services.AddMemoryCache();
              services.AddSession();
          }
  
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              app.UseStatusCodePages();
              app.UseStaticFiles();
              app.UseMvcWithDefaultRoute();
              app.Run(async (context) =&gt;
              {
                  await context.Response.WriteAsync(Configuration["Message"]);
              });
          }
      }
  }
  </code></pre>
  
  <p>program class:</p>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          BuildWebHost(args).Run();
      }
  
      public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .ConfigureAppConfiguration((context, builder) =&gt; builder.SetBasePath(context.HostingEnvironment.ContentRootPath)
                         .AddJsonFile("appsettings.json")
                         .Build())
  
              .UseStartup&lt;Startup&gt;()
              .Build();
  }
  </code></pre>
  
  <p>appsettings.json:</p>
  
  <pre><code>{
    "Message": "Hello World",
    "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=NotMyFault;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
  }
  </code></pre>
  
  <p>Interestingly if I run the app, it displays "Hello World", but when add migration it cannot find connectionString. Can someone please shed some lights here? Thanks.</p>