无法加载文件或程序集工具实体框架 .PowerShell.Utility.dll'.
本文关键字:Utility PowerShell dll 框架 实体 加载 文件 工具 程序集 | 更新日期: 2023-09-27 17:55:56
尝试从程序包管理器控制台安装实体框架 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
如您所见,有例外。但毕竟,尽管有例外,实体框架 6.1.3 还是成功添加到项目中。此外,当我添加对System.Data.Entity的引用时,并尝试在代码中使用它。我无法连接到 System.Data.Entity 命名空间并使用此命名空间的库。它是否以某种方式连接到上述异常,以及如何解决此问题?
使用以下命令:
EntityFramework6'Add-Migration
Microsoft已更改cmdmidlet
的名称
我通过将实体框架 6.1.3 降级为实体框架 6.1.2 来解决此问题。
我刚刚在.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
从项目中卸载 EntityFramework,然后重新启动项目并重新安装 EntityFramework
这是通过将解决方案中的所有 EF 项目升级到相同的 EF 版本来解决的。我不同意 MS 产品很糟糕。我喜欢VS IDE环境。没有什么能比得上它。
我使用的是EF版本6.4.4。更改为 6.2.0 解决了问题。
如果未在包管理器控制台中选择正确的"默认项目",则可能会出现此错误。 将其切换到您的主应用程序项目,它将起作用。
或者,您可以使用如下所示的-ProjectName
选项:
Add-Migration -Name "Some changes" -ProjectName MyWebProject
我遇到了类似的错误,并通过提取EntityFramework.6.1.3.nupkg中的所有工具文件夹来解决。 您可以在此文件夹中找到此包:
[your solution directory]'packages'EntityFramework.6.1.3)
根据 @maksym-trubaiev 的回答,我意识到您可以简单地删除旧的 EF 文件夹,然后就不会再有任何混淆
了$ rm -r packages/EntityFramework.6.1.3/
(就我而言,6.1.3
是旧版本,因为我升级到6.4.4
)
在我的情况下,将 Dll 从 EF 6.4.4 更改为 EF 6.0.0 修复它
,这发生在我创建一个.NetStand (2.1) 项目引用了具有 EF (6.1) 依赖项的 NuGet 包。
卸载包 实体框架 -强制安装包实体框架 - 版本 6.1.2启用迁移
通过将所有项目升级到最新的 EntityFramework (6.4.4) 来解决