Q:

Value cannot be null. Parameter name: connectionString when i run add-migration

I am trying to write my connection string in my appsettings.json file and bring it into my startup file but I keep getting a Value cannot be null. Parameter name: connectionString.
I had the following error in package manager console when Add-Migration.
This is my startup:

namespace WebApi
{

    public class Startup
    {

        private string _connectionString = null;

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            _connectionString = Configuration["secretConnectionString"];
            services.AddMvc();
  
            services.AddEntityFrameworkNpgsql().AddDbContext<ApiContext>
                (Options => Options.UseNpgsql(_connectionString));

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
        }
    }
}

appsettings.json:

"connectionString": {
    "_connectionString": " User Id=Pdev; Password=abcd;Server=localhost;Port=5432;Database=Advantage.Api.Dev;Integrated Security=true;Pooling=true;"
  },

A:

Instead of
_connectionString = Configuration["secretConnectionString"];

try using
_connectionString = Configuration.GetValue<string>(
                "connectionString:_connectionString")

