ef添加迁移错误
问题描述:
我有几个类文件。但现在我添加了新的模型类,并尝试输入添加迁移InitialCreate。但是我收到以下错误。ef添加迁移错误
PM> add-migration InitialCreate
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\user\Documents\Visual Studio 2013\Pro
jects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operati
on is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 c
har: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 C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 c
har: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:///C:\Users\user\Documents\Visual Studi
o 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Opera
tion is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 c
har:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
PM>
答
使用软件包管理器,你需要重新安装实体框架:
卸载,包的EntityFramework -Force
然后安装它为每个项目:
Install-Package EntityFramework
然后不要忘记重新开始工作室。
答
我今天有一个稍微不同的情况下,我在这里wirting细节的情况下,这可能帮助别人。错误引用了我的一个程序集,而包含EF DbContext的程序集依赖于此程序集。
我解决了它将引用的程序集设置为“Copy Local”“true”,因此在构建迁移时会创建本地副本,因此能够找到它。
答
您需要重新安装实体框架: