实体框架代码首先迁移抛出错误

2024-04-09

这是我在收到此错误之前所做的操作:

  1. 安装了 EF(预发布版本,可能是 6,我不知道)
  2. 决定我不想要,所以卸载它并重新安装稳定版本 (5)
  3. 通过 SSMS 截断我的数据库

这是错误:

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or      
assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicK
eyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest   
definition does not match the assembly reference. (Exception from H
RESULT: 0x80131040)"
At C:\Projects\BCATracker.Web\packages\EntityFramework.6.0.0- 
alpha2\tools\EntityFramework.psm1:425 char:31
+     $domain.CreateInstanceFrom <<<< (
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation

这是我尝试过的:

  • 删除bin目录中的所有内容,重建。
  • 从nuget中删除EF,删除packages目录中的文件,在nuget中readd ef。

查看 proj 文件,我看到以下内容:

<Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>

可能的根本原因是什么?


我解决了这个问题。 EntityFramework.dll 需要位于 Visual Studio 的 GAC 中才能从包管理器中使用它。

  1. 启动 Visual Studio 命令提示符(确保您以管理员身份启动 Visual Studio)
  2. 转到您的包目录并找到 EntityFramework 包目录。
  3. 转到 lib\net45(如果目标为 4.5)
  4. 类型:gacutil /i EntityFramework.dll

注意:此时完全重新启动计算机可能是明智之举。

我不确定为什么 Visual Studio 不再看到 DLL,但这让我解决了这个问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

实体框架代码首先迁移抛出错误 的相关文章

随机推荐