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

时间:2016-07-08 14:20:00

标签: c# entity-framework visual-studio-2015

尝试从Package Manager控制台安装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的引用,并尝试使用它在code.I无法连接到System.Data.Entity命名空间并使用此命名空间的库。它是否以某种方式连接到上面提到的异常,以及如何解决这个问题?

9 个答案:

答案 0 :(得分:3)

我通过将Entity Framework 6.1.3更新为Entity Framework 6.1.2解决了这个问题。可能是上一版本的bug。

答案 1 :(得分:2)

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

答案 2 :(得分:1)

使用EntityFramework6 \ Add-Migration命令,Microsoft更改了cmdmidlet的名称

答案 3 :(得分:0)

我收到类似的错误并通过解压缩EntityFramework.6.1.3.nupkg中的所有工具文件夹来解决。您可以在此文件夹中找到此包:

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

基于@ maksym-trubaiev的答案,我意识到您只需删除旧的EF文件夹,就不会再有任何混淆了

$ rm -r packages/EntityFramework.6.1.3/

(在我的情况下,6.1.3是旧版本,因为我升级到6.4.4

答案 6 :(得分:0)

就我而言,将Dll从EF 6.4.4更改为EF 6.0.0即可解决

答案 7 :(得分:0)

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

或者,您可以像这样使用 -ProjectName 选项:

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

答案 8 :(得分:-1)

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

解决方案原为(Package Manager控制台):

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

我越来越喜欢开源,因为这种M $“解决方案”永远不会但永远不会真正起作用。