c# - 启用迁移时出错

标签 c# .net entity-framework asp.net-mvc-4

我是 EF 的新手,当我尝试在 PMC 控制台中运行 Enable-Migrations 时出现错误: 使用“1”个参数调用“LoadFrom”时出现异常:

 "Could not load file or assembly 'file:///...\pa
ckages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:780 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 ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:781 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:///...\packages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is no t supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:809 char:31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

最佳答案

我刚刚在我同事的一台机器上遇到了这个问题。解决方案是:

  1. 卸载 EF NuGet 包
  2. 从 Web.Config/App.Config 文件中手动删除 Entity Framework 部分
  3. 关闭 Visual Studio
  4. 在 Visual Studio 中重新打开解决方案
  5. 重新安装 EF NuGet 包

关于c# - 启用迁移时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25265015/

相关文章:

c# - 如何从一种方法中使用的类访问不同方法中的信息?

c# - 如何使用 Entity Framework 自动包含所有底层导航属性

c# - ASP.NET MVC5 - 如何强制 Entity Framework 忽略模型中的属性?

c# - 阻止用户选择但允许以编程方式选择

c# - 影响我域的 Entity Framework

c# - 如何编写一个桌面应用程序来读取/写入数据到连接到 PC 的 symbian 手机

c# - 使用 LINQ 仅从表中获取所需的列以修改和保存记录会出现典型错误

c# - 获取 ComboBox 中所选项目的 ID

c# - 将 Json 反序列化为 C# bool

C# : Out of Memory exception