Search code examples
entity-frameworkasp.net-identity

Using Asp.net Identity in with Entity Framework throws Could not load type .Schema.IndexAttribute' from assembly 'EntityFramework, Version=6.0


public EmployeeDTO AuthenticateEmployee(string username, string password)
{
    try
    {
        var userLogin = UnitOfWork.UserLoginRepository.Get(x => x.UserName == username).FirstOrDefault();

        if (userLogin == null)
            return null;
        else
        {
            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);

            // this throws an error.
            var user = userManager.Find("username", "password");
        }
    }
}

Results in error:

Could not load type 'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I'm using EF 6.0, Microsoft.AspNet.Identity.EntityFramework Ver 2.0.

I couldn't perform any action based on EF using Identity is there anything I have to do, my EDMX is in another class library. I think its a DLL issue.

Please help me to use identity with EF.

I have gone through Msdn


Solution

  • IndexAttribute is one of the new things included in EF 6.1. So the problem is that you're referencing the wrong EF version (6.0). Please reference 6.1 in your project.

    Look at EF Version History.