当模型发生变化时,WebAPI 2中的EF标识停止工作
问题描述:
我想使用Android/iOS可以使用的Web服务在Angular中构建网站。我终于找到了一个很棒的教程,帮助我设置了这个教程。下一步是扩展身份模型。所以,我添加了一个属性。然后,我开始得到一个异常:。当模型发生变化时,WebAPI 2中的EF标识停止工作
“的模式支持了‘AuthContext’语境自创建数据库时改变考虑使用代码首先迁移到更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)
所以,当我遵守这些指示,我得到这个:
Enable-Migrations
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.PowerShell.
Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\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 C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\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:///C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.P
owerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.psm1:809 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
PM> Enable-Migrations -ContextTypeName AngularJSAuthentication.API.AuthContext
The project 'AngularJSAuthentication.API' failed to build.
PM> Enable-Migrations -ContextTypeName AngularJSAuthentication.API.AuthContext
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.PowerShell.
Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\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 C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\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:///C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.P
owerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.psm1:809 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
PM> Enable-Migrations
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.PowerShell.
Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\copa\AngularJSAuthentication-master\packages\EntityFramework.6.1.0\tools\EntityFramework.psm1:780 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我已经改变了我的初始化器在启动(注释表明它是什么)
Database.SetInitializer<AuthContext>(null);// <AuthContext>());//, AngularJSAuthentication.API.Migrations.Configuration>());
并在上下文类静态构造函数(这个组合是我在另一个项目中所做的那样)
static AuthContext()
{
Database.SetInitializer<AuthContext>(new AuthContextInitialiser());
}
我很茫然,我GOOGLE了,但我看到的解决方案,不似乎工作。 VS正在以管理员身份运行。我只是想EF不关心我的数据库,并相信我,它应该是这样...
其实,如果我告诉它取代我的数据库(我不喜欢),我得到这个错误:
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration
没有,只是留下我一个人相信我能管理自己的数据库路径...
感谢
答
此异常和HResult的代码来,如果有一个安全限制防止组件被加载。
的常见原因:
- 网络共享或驱动器:将文件复制到硬盘
- DLL从其他机器复制:右键单击并解锁
有人可以告诉我,我”米做错了吗?没有人回答我.... – cgraus