尝试使用Generate Views
EntityFramework Power Tools (0.9 beta) 的功能时,生成失败,并且在输出窗口出现以下错误:
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.TypeLoadException: Could not load type
'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' from assembly
'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at MyProject.Entities.Models.MyDbContext.OnModelCreating(DbModelBuilder modelBuilder)
我的上下文继承自IdentityDbContext
,当电动工具尝试为身份模型生成视图时,似乎是什么导致了这个问题。
仅在尝试生成视图时才会发生这种情况。解决方案本身构建和运行没有任何错误。
为了简化和隔离这个问题,我在 vs 2013 中创建了一个带有身份和实体框架 6.0 的新网站项目,并且生成工作正常。将包更新到 Identity 2.2.1 和 EntityFramework 6.1.3 会导致错误并且生成失败。
我检查了项目引用,看起来引用了正确的 Entityframework 版本。
我的 .csproj 参考资料:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.EntityFramework">
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.1\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
</Reference>
好像 Power 工具坚持使用 6.0 版本还没有该System.ComponentModel.DataAnnotations.Schema.IndexAttribute
类型,因为它只在 6.1 版本中引入,但它被添加到最新的 Identity 模型中以限制唯一的 UserName。
有什么想法吗?