Asp.net
啟用 Code First Entity Framework VS Web Express 2012
我正在嘗試在我的 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 搜尋和排除故障。有人對我如何解決這個問題有任何想法嗎?
我已經兩次遇到這個問題了。兩次我都必須解除安裝實體框架,然後為解決方案中的每個項目重新安裝它。我花了一段時間才弄清楚第二次這樣做的一件事是,我必須在重新安裝實體框架後重新啟動 Visual Studio (2012)(或者我繼續收到“無法載入文件或程序集”
$$ path $$\packages\EntityFramework.5 .0.0\tools\EntityFramework.PowerShell.Utility.dll’”錯誤)。 要進入包管理器控制台,請轉到:工具 -> 庫包管理器 -> 包管理器控制台
在包管理器中為每個項目解除安裝實體框架(我從包管理器控制台頂部的預設項目下拉列表中選擇了每個項目):
Uninstall-Package EntityFramework -Force
然後為每個項目安裝它:
Install-Package EntityFramework
此時嘗試執行 Enable-Migrations 命令仍然出現錯誤,直到我關閉並重新啟動 Visual Studio。然後它成功了,Update-Database 命令也是如此(在 Migrations.Configuration 文件中將 AutomaticMigrationsEnabled 設置為 true 之後)。