Search code examples
entity-frameworkvisual-studioasp.net-identityef-power-tools

EntityFramwork Power Tools error while generating views


When trying to use the Generate Views function of EntityFramework Power Tools (0.9 beta), the generation fails and I get the following error at the Output window:

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)

My context inherits from IdentityDbContext, what seems to cause this issue when the power tools tries to generate views for the Identity models.

This happens only wen trying to generate the views. The solution itself builds and runs without any errors.

To simplify and isolate this problem I've created a new website project in vs 2013 with identity and entity framework 6.0 and the generation works fine. updating the packages to Identity 2.2.1 and EntityFramework 6.1.3 causes the error and the generation fails.

I've checked the project references and it looks like the right Entityframework version is referenced.

My .csproj references:

<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>

Seems like the Power tools is insisting of using the 6.0 version that dont have the System.ComponentModel.DataAnnotations.Schema.IndexAttribute type yet, since it has only introduced at the 6.1 version, but it was added to the latest Identity models to restrict unique UserName.

Any thoughts?


Solution

  • Turns out the the Power tools is using the Visual Studio IDE version of EntityFramework, and not the referenced one from the project. In my case it was 6.0.2. Installing Visual Studio 2013 Update 5 (2013.5) RTM on my machine solved the problem, and the latest EntityFramework 6.1.3 is now used.