I am fairly new to both EF and .NET Core, but using a working project I was able to build a Core 2.0 Web API solution. The only issue is I am unable to get Entity Framework to instantiate on startup. I am receiving an error stating:
System.ArgumentNullException: Value cannot be null. Parameter name: connectionString
My Startup.cs file:
public class Startup
{
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)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("dbc")));
services.AddMvc();
}
// 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();
}
}
My validated JSON file:
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"dbc": "Server=cc;Initial Catalog=dd;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}
UPDATE My Program.Cs
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}