我正在尝试在我的 Visual Studio Web Express 2012 中启用 Code First。从我目前所读到的内容来看,我必须使用包管理器控制台和命令 Enable-Migrations。当我这样做时,我收到以下错误。
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $toolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:399 char:50
+ $dispatcher = $utilityAssembly.CreateInstance <<<< (
+ CategoryInfo : InvalidOperation: (CreateInstance:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityF
ramework.5.0.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
如您所见,这是一个非常大的错误,因此很难通过 google 进行故障排除。有没有人对我如何解决这个问题有任何想法?
最佳答案
我现在遇到过两次这个问题。两次我都不得不卸载 Entity Framework ,然后为解决方案中的每个项目重新安装它。第二次我花了一段时间才弄清楚的一件事是,我必须在重新安装 Entity Framework 后重新启动 Visual Studio (2012)(或者我继续收到“无法加载文件或程序集” [路径]\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll'”错误)。
要进入包管理器控制台,请转到:工具 -> 库包管理器 -> 包管理器控制台
在包管理器中为每个项目卸载 Entity Framework (我从包管理器控制台顶部的默认项目下拉列表中选择了每个项目):
Uninstall-Package EntityFramework -Force
然后为每个项目安装它:
安装包 Entity Framework
此时尝试运行 Enable-Migrations 命令仍然出现错误,直到我关闭并重新启动 Visual Studio。然后它就成功了,Update-Database 命令也是如此(在 Migrations.Configuration 文件中将 AutomaticMigrationsEnabled 设置为 true 之后)。
关于asp.net - 启用代码优先 Entity Framework VS Web Express 2012,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12318107/