无法加载类型

8
首先感谢您的时间,希望即使我英语不太好,您也能理解我的翻译:

从程序集“Microsoft.EntityFrameworkCore, Version=3.0.0.0,Culture=neutral, PublicKeyToken=adb9793829ddae60”中无法加载类型'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsExtensionWithDebugInfo'

我尝试重新安装所有包,手动添加引用,重启电脑,重启VS2019,甚至新建项目,但错误仍然存在。

我在这里看过,但没有帮助。

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(


Configuration.GetConnectionString("DefaultConnection")));

--.csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>aspnet-ZavrsniRad01-F04B6A7E-6450-4254-8092-F42843F4615A</UserSecretsId>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0-preview6.19307.2" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0-preview6.19307.2" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0-preview6.19307.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview.18572.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview6.19304.10" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0-preview6.19304.6" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview6-19319-03" />
  </ItemGroup>

</Project>

请展示您的 packages.config.csproj 文件。 - vasily.sib
2
你看过这个吗?https://github.com/aspnet/EntityFrameworkCore/issues/15192 - jefftrotman
我已经放置了.csproj文件,但无法找到package.config文件。当我尝试将第二个DbContext添加到StartUp文件时出现了错误。 - Insane Shadow
@jefftroman 我已经将我的 EFC SQL 更新到 3.0,但结果仍然相同。 - Insane Shadow
3个回答

8

显然我需要安装EntityFrameworkCore.SqlServer预览版6来解决这个错误。

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.0.0-preview6.19304.10

这也解决了我的问题。谢谢!我在 Github 的问题串中发布了此信息,以帮助他人。https://github.com/MicrosoftDocs/visualstudio-docs/issues/3698 - Kellen Stuart

4

我的测试项目也遇到了同样的问题,我发现我的测试包中缺少了 Microsoft.EntityFrameworkCore.SqlServer,所以我安装了最新版本的它,问题得以解决。

注意:如果你在测试中遇到了同样的问题,请确保 Microsoft.EntityFrameworkCore.InMemory 的版本与 Microsoft.EntityFrameworkCore.SqlServer 相匹配,以保持一致性。

enter image description here


2
我也遇到了这个错误信息,但根本原因是与延迟加载相关的代理包缺失。安装Microsoft.EntityFrameworkCore.Proxies解决了我的问题。
Install-Package Microsoft.EntityFrameworkCore.Proxies -Version 3.1.8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接