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

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

当尝试从包管理器控制台安装 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

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

c# entity-framework visual-studio-2015
13个回答
63
投票

使用命令:

EntityFramework6\Add-Migration

Microsoft 已更改名称

cmdmidlet


11
投票

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


5
投票

从您的项目中卸载EntityFramework然后restart您的项目和reinstallEntityFramework


5
投票

我刚刚在 .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
 

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

Uninstall-Package EntityFramework -Force
Install-Package EntityFramework -Version 6.1.2
Enable-Migrations

4
投票

对我来说,这是通过将解决方案中的所有 EF 项目升级到相同的 EF 版本来解决的。我不同意 MS 产品很烂。我喜欢 VS Ide 环境。没有什么比得上它了。


2
投票

我使用的是 EF 版本 6.4.4。更改为 6.2.0 解决了问题。


1
投票

如果您没有在包管理器控制台中选择正确的“默认项目”,您可能会收到此错误。将其切换到您的主要应用程序项目,它将起作用。

或者你可以像这样使用

-ProjectName
选项:

Add-Migration -Name "Some changes" -ProjectName MyWebProject


0
投票

我遇到了类似的错误,并通过提取 EntityFramework.6.1.3.nupkg 中的所有工具文件夹来解决。你可以在这个文件夹中找到这个包:

[your solution directory]\packages\EntityFramework.6.1.3)

0
投票

根据@maksym-trubaiev 的回答,我意识到你可以简单地删除旧的 EF 文件夹,然后就不会再有任何混淆了

$ rm -r packages/EntityFramework.6.1.3/

(在我的例子中,

6.1.3
是旧版本,因为我升级到
6.4.4


0
投票

在我的例子中,将 Dll 从 EF 6.4.4 更改为 EF 6.0.0 修复它


0
投票

对我来说,这发生在我创建一个 .NetStand (2.1) 项目时,该项目引用了一个具有 EF (6.1) 依赖项的 NuGet 包。


0
投票

卸载包 EntityFramework -Force 安装包 EntityFramework - 版本 6.1.2 启用迁移


0
投票

通过将解决方案中的所有项目升级到最新的 EntityFramework (6.4.4) 来解决

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