无法加载文件或程序集工具\EntityFramework .PowerShell.Utility.dll'

Far*_*cos 12 c# entity-framework visual-studio-2015

尝试从包管理器控制台安装 Entity Framework 6.1.3 时。我得到以下输出。

Install-Package EntityFramework 
Attempting to gather dependency information for package 'EntityFramework.6.1.3' with respect to project 'OnlineShop', targeting '.NETFramework,Version=v4.6.1'
Attempting to resolve dependencies for package 'EntityFramework.6.1.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'EntityFramework.6.1.3'
Resolved actions to install package 'EntityFramework.6.1.3'
Adding package 'EntityFramework.6.1.3' to folder 'D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages'
Added package 'EntityFramework.6.1.3' to folder 'D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages'
Added package 'EntityFramework.6.1.3' to 'packages.config'
Executing script file 'D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\EntityFramework.6.1.3\tools\install.ps1'
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or asse
mbly 'file:///D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop
\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' o
r one of its dependencies. The system cannot find the file specified."
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path $Too
lsP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

You cannot call a method on a null-valued expression.
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load fi
le or assembly 'file:///D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\
OnlineShop\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll'
 or one of its dependencies. The system cannot find the file specified."
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:809 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or asse
mbly 'file:///D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop
\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' o
r one of its dependencies. The system cannot find the file specified."
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path $Too
lsP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

You cannot call a method on a null-valued expression.
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load fi
le or assembly 'file:///D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\
OnlineShop\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll'
 or one of its dependencies. The system cannot find the file specified."
At D:\Leva\Work\Informatika\CSharp\My OPENSOURCE projects\OnlineShop\packages\E
ntityFramework.6.1.3\tools\EntityFramework.psm1:809 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException


Type 'get-help EntityFramework' to see all available Entity Framework commands.
Successfully installed 'EntityFramework 6.1.3' to OnlineShop
Run Code Online (Sandbox Code Playgroud)

如您所见,存在异常。但毕竟,Entity Framework 6.1.3 已成功添加到项目中,尽管存在异常。此外,当我添加对 System.Data.Entity 的引用并尝试在代码中使用它时。我无法连接到 System.Data.Entity 命名空间并使用此命名空间的库。它是否以某种方式连接到上述异常,以及如何解决这个问题?

小智 31

使用 EntityFramework6\Add-Migration 命令,微软已经更改了 cmdmidlet 的名称

  • 谢谢,它对我有用 PM> EntityFramework6\Add-Migration -ConfigurationTypeName ProjectNAME.DataContexts.DbMigrations.Configuration "Abc123456" (2认同)

Far*_*cos 10

我通过将 Entity Framework 6.1.3 降级到 Entity Framework 6.1.2 解决了这个问题。可能是上一个版本的错误。

  • 这对我有用 EntityFramework V6.4.0,低至 V6.2.0 (2认同)

Chr*_*utt 6

我刚刚在 .NET Framework 4.5 项目中的 Visual Studio 2019 (v16.5.4) 中使用 EntityFramework 6.4.0 时遇到了同样的问题。

PM> Enable-Migrations
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\Administrator\source\repos\InfrastructureManager\packages\EntityFramework.6.4.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. The system cannot find the file specified."
At C:\Users\Administrator\source\repos\InfrastructureManager\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 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 C:\Users\Administrator\source\repos\InfrastructureManager\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///C:\Users\Administrator\source\repos\InfrastructureManager\packages\EntityFramework.6.4.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. The system cannot find the file specified."
At C:\Users\Administrator\source\repos\InfrastructureManager\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException
 
Run Code Online (Sandbox Code Playgroud)

解决方案是(包管理器控制台):

Uninstall-Package EntityFramework -Force
Install-Package EntityFramework -Version 6.1.2
Enable-Migrations
Run Code Online (Sandbox Code Playgroud)


小智 5

从项目中卸载EntityFramework ,然后重新启动项目并重新安装EntityFramework


小智 5

对我来说,这是通过将解决方案中的所有 EF 项目升级到相同的 EF 版本来解决的。我不同意微软的产品很糟糕。我喜欢 VS Ide 环境。没有什么可以与之相比。