Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute'

I am having this Error. Could not load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' ERROR

The ApplicationDbContext is Auto Generated DbContext, used in account section. Whenever i try to use any Account Controller actions this error occurs. The error originates from

  public AccountController()
            : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
        {
        }

I have my own DbContext which works fine and gets all the required Data.

The references are fine. How do i fix this issue.

Update I used some updated Refrences for AspNet.Identity . is it causing the issue?

Update 2 This error occured when I was mixing two Membership provider versions. I first used the default provided with MVC 5 then tried to use MVC 3 membership, then again went back to MVC 5. Then this error started to pop up.

I still have not found the solution to this problem. But as workaround, I recreated the Project will all my previous files, and it worked.

like image 923
Ruchan Avatar asked May 12 '14 10:05

Ruchan


3 Answers

Edit your .csproj file, and replace the <HintPath> values with the correct Entity Framework version paths (currently, the latest stable version is 6.1.2):

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>

Verify that the paths exist; if not, install the Nuget package for the version you want.

To be clear, these are the <HintPath> elements you want to edit to ensure have the current version:

<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>

and

<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>

Leave these set to the major version 6.0.0.0:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">

And

<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
like image 183
Chris Schiffhauer Avatar answered Oct 10 '22 12:10

Chris Schiffhauer


I got the same problem and I've tried to modify my .csproj file and replace the <HintPath> like what Chris Schiffhauer has showed above but the problem was not solved. Finally, I found out that entity framework dll in my GAC was an old version (6.0.0.0), after removing it, no more problem.

You can easily find it here C:\Windows\Microsoft.NET\assembly\GAC_MSIL

like image 22
tuan nguyen Avatar answered Oct 10 '22 13:10

tuan nguyen


I had a similar error with a test project, both projects had a reference to entity framework 6.0.0.0. I was able to solve it by removing and adding the reference to entity framework again in the test project.

like image 25
Christian S Avatar answered Oct 10 '22 11:10

Christian S