我正在使用 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 包(即实体框架)并且它可以工作。 但这很烦人,而且绝对不是解决方案。寻找永久解决方案。 预先感谢。
就我而言,我正在执行
添加迁移
命令。相反,我用了
EntityFramework6\添加迁移
我没有再犯任何错误。 (感谢这个答案,我找到了https://stackoverflow.com/a/58951090/2546759)
另一件事做到了这一点是:
此工作 EntityFramework6\Add-Migration