值不能为空。参数名称:connectionString

时间:2019-04-29 07:07:20

标签: c# .net-core

我正在使用asp.net core 2.2版本

下面是我的appSettingsDevelopment.JSON

{ 
 "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=DatingApp.db"
  }
}

下面是我的.csproj

    <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
  </ItemGroup>

</Project>

下面是我访问连接字符串的方式

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

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<DataContext>(x => 
         x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

我已经阅读并阅读了所有相关的主题,但是以某种方式我无法解决此问题。 我收到以下提到的错误:

  

尝试激活“ Dating.API.Data.DataContext”时,无法解析类型为“ Microsoft.EntityFrameworkCore.DbContextOptions`1 [Microsoft.EntityFrameworkCore.DbContext]”的服务。

0 个答案:

没有答案