0

尝试使用Generate ViewsEntityFramework 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。

有什么想法吗?

4

1 回答 1

0

原来 Power 工具使用的是 Visual Studio IDE 版本的 EntityFramework,而不是项目中引用的版本。就我而言,它是 6.0.2。在我的机器上安装Visual Studio 2013 Update 5 (2013.5) RTM解决了这个问题,现在使用的是最新的 EntityFramework 6.1.3。

于 2016-01-19T06:46:48.757 回答