简体   繁体   English

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

[英]While I'm working ins asp.net core 3.1 getting this error Value cannot be null. (Parameter 'connectionString')

System.ArgumentNullException: 'Value cannot be null. System.ArgumentNullException: '值不能为空。 (Parameter 'connectionString') (参数'connectionString')

I am getting this error I think that problem brings from appsetting.json but I can't find it我收到此错误我认为该问题来自 appsetting.json 但我找不到它

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

Error bring from _config.GetConnectionString("EmployeeDbConnection)错误来自 _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();
        }

The reason is in your appsettings.json :原因在您的appsettings.json

Change the code to( ConnectionString to ConnectionStrings ):将代码更改为( ConnectionStringConnectionStrings ):

 "AllowedHosts": "*",
   "ConnectionStrings": {
    "EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Asp.Net Core 2.0 ArgumentNullException:值不能为null。 参数名称:connectionString - Asp.Net Core 2.0 ArgumentNullException: Value cannot be null. Parameter name: connectionString System.ArgumentNullException:值不能为 null。(参数“connectionString”)asp.net 核心 Docker-compose - System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString') asp.net Core Docker-compose 单元测试 ASP.NET 核心 3.1 MVC controller - 值不能是 null。 (参数“提供者”) - Unit testing ASP.NET Core 3.1 MVC controller - value cannot be null. (Parameter 'provider') 从 package 控制台管理器更新数据库时出现此错误值不能是 null。 (参数“连接字符串”) - While updating database from package console manager getting this error Value cannot be null. (Parameter 'connectionString') 值不能为空。 尝试使用 JsonConverter .net core 3.1 反序列化对象时出现(参数“值”)错误 - Value cannot be null. (Parameter 'value') error when trying to DeserializeObject using JsonConverter .net core 3.1 .NET 核心工作者异常:值不能是 null。 参数名称连接字符串 - .NET Core worker exception: Value cannot be null. Parameter name connectionString ASP.NET Core 5 MVC:ArgumentNullException:值不能为空。 (参数“项目”) - ASP.NET Core 5 MVC: ArgumentNullException: Value cannot be null. (Parameter 'items') 值不能是 null。 (参数“主体”)[身份][ASP.net核心] - Value cannot be null. (Parameter 'principal') [ Identity ] [ ASP.net core ] ASP.NET Core 2.0 值不能为空。 参数名称:名称 - ASP.NET Core 2.0 Value cannot be null. Parameter name: Name 值不能是 null。 ASP.NET Core 3..0 中的(参数'key') - Value cannot be null. (Parameter 'key') in ASP.NET Core 3..0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM