Failed to load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute'

I have this error. Could not load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' ERROR

ApplicationDbContext is an automatically created DbContext used in the account section. Whenever I try to use any actions of the account controller, this error occurs. The error arises from

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

I have my own DbContext, which works fine and receives all the necessary data.

The links are good. How to fix this problem.

Update I used some updated Refrences for AspNet.Identity. does this cause a problem?

Update 2 This error occurred when I mixed two versions of the membership provider. First I used the default value provided by MVC 5, then I tried to use MVC 3 membership, and then returned to MVC 5 again. Then this error started to pop up.

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

+7
c # entity-framework dbcontext data-annotations
source share
2 answers

Modify the .csproj file and replace the <HintPath> values ​​with the correct paths of the Entity Framework version (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> 

Make sure there are ways; if not, install the Nuget package for the correct version.

To be clear, these are the <HintPath> elements that you want to edit to 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 them in the main 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"> 
+10
source share

I had a similar error with a test project, both projects had a reference to the framework 6.0.0.0 entity. I was able to solve this problem by deleting and adding a link to the entity structure again in the test project.

0
source share

All Articles