每当我重新打开 Visual Studio 2019 时,实体框架都会给出错误“无法加载文件或程序集”、“FileNotFoundException”

问题描述 投票:0回答:2

我正在使用 Visual Studio 2019 Ent 和 EntityFramework.6.4.4。 每当我重新启动 VS19 并要访问 EF 时,使用代码优先方法都会出现以下错误。

 Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///("Project Name")\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. The 
system cannot find the file specified."
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:782 char:5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-P ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException
 
You cannot call a method on a null-valued expression.
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:783 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///"(Project Name)"\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.dll' or one of its dependencies. The system 
cannot find the file specified."
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:811 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

到目前为止我已经尝试过: 我找到了一个临时解决方案,通过每次重新安装 nugete 包(即实体框架)并且它可以工作。 但这很烦人,而且绝对不是解决方案。寻找永久解决方案。 预先感谢。

c# asp.net-mvc ef-code-first visual-studio-2019 entity-framework-6.4
2个回答
6
投票

就我而言,我正在执行

添加迁移

命令。相反,我用了

EntityFramework6\添加迁移

我没有再犯任何错误。 (感谢这个答案,我找到了https://stackoverflow.com/a/58951090/2546759

另一件事做到了这一点是:

  1. 确保解决方案中的所有项目都使用相同的 EF 版本。
  2. 重新启动 Visual Studio。

(如此处建议:https://stackoverflow.com/a/70004476/2546759


0
投票

此工作 EntityFramework6\Add-Migration

© www.soinside.com 2019 - 2024. All rights reserved.