小编Rem*_*yev的帖子

当我在 asp.net core 3.1 中工作时收到此错误值不能为空。(参数'connectionString')

System.ArgumentNullException: '值不能为空。(参数'connectionString')

我收到此错误我认为该问题来自 appsetting.json 但我找不到它

 "AllowedHosts": "*",
    "ConnectionString": {
        "EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
    }
Run Code Online (Sandbox Code Playgroud)

错误来自 _config.GetConnectionString("EmployeeDbConnection)

public Startup(IConfiguration config)
        {
            _config = config;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
           
            services.AddDbContextPool<AppDbContext>(options => options.UseSqlServer(_config.GetConnectionString("EmployeeDbConnection")));
            
            services.AddScoped<IEmployeeRepository, SqlServerRepository>();
            services.AddMvc(options => options.EnableEndpointRouting = false).AddXmlSerializerFormatters();
        }
Run Code Online (Sandbox Code Playgroud)

c# model-view-controller asp.net-core

3
推荐指数
1
解决办法
128
查看次数

标签 统计

asp.net-core ×1

c# ×1

model-view-controller ×1