Looking for some insight into this issue. To me, it looks like all the configuration aligns with what is expected, but whenever i try to run dotnet publish TestAPI.dll
and attempt to hit an endpoint, I see the following:
ArgumentNullException: Value cannot be null. Parameter name: connectionString Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(string value, string parameterName) Microsoft.EntityFrameworkCore.Infrastructure.RelationalOptionsExtension.WithConnectionString(string connectionString) Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL(DbContextOptionsBuilder optionsBuilder, string connectionString, Action MySQLOptionsAction) TestAPI.Startup.b__4_0(DbContextOptionsBuilder options) in Startup.cs + options.UseMySQL(Configuration.GetConnectionString("DefaultConnection"))); Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions+<>c__DisplayClass0_0.b__0(IServiceProvider p, DbContextOptionsBuilder b) Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory(IServiceProvider applicationServiceProvider, Action optionsAction) Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions+<>c__DisplayClass5_0.b__0(IServiceProvider p) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite, TArgument argument)
I can confirm that it's working as expected when I run the application from the IDE (Visual Studio for Mac). Here's my relevant config:
appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "server=localhost;userid=root;pwd=root;port=3306;database=Expenses;sslmode=none;"
},
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
//"Console": {
// "LogLevel": {
// "Default": "Warning"
// }
//}
}
}
appsettings.Development.json
{
"ConnectionStrings": {
"DefaultConnection": "server=localhost;userid=root;pwd=root;port=3306;database=Expenses;sslmode=none;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TestAPI.Data;
using TestAPI.Data.Models;
using System;
using Microsoft.Extensions.Logging;
namespace TestAPI
{
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.AddCors();
services.AddMvc();
services.AddDbContext<ExpensesDbContext>(options =>
options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<IBaseDa<Accounts>, AccountsDataAccess>();
services.AddTransient<IExpensesDa, ExpensesDa>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
env.EnvironmentName = "Development";
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseMvc();
}
}
}
Program.cs
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace TestAPI
{
public class Program
{
public static void Main(string[] args)
{
//var builder = new ContainerBuilder();
//// register types here for DI
//builder.RegisterType<AccountsDataAccess>().As<IBaseDa<Accounts>>();
//_container = builder.Build();
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
even tried editing the appsettings.Development.json and appsettings.json within the corresponding publish folder (e.g. bin/Release/netcoreapp2.0/publish)
Any help is greatly appreciated! Thanks all