ASP.NET Core 2.1 Identity couldn't find ApplicationUser

SalmanShariati picture SalmanShariati · Aug 25, 2018 · Viewed 9.2k times · Source

I've included Identity into my .NET Core2.1 project, when I try to build the project, it warns me with the following error:

The type or namespace name 'ApplicationUser' couldn't be found (are you missing a using directive or an assembly reference?)

Should I define ApplicationUser myself or Identity will create it by itself?

any help would be appreciated.

Answer

Ruard van Elburg picture Ruard van Elburg · Aug 25, 2018

You'll have to create the ApplicationUser class yourself. The default user is IdentityUser. ApplicationUser inherits from IdentityUser:

public class ApplicationUser : IdentityUser
{
}

But if you are not extending ApplicationUser then you can also use IdentityUser. So instead of this:

services.AddIdentity<ApplicationUser, IdentityRole>()

you can use this:

services.AddIdentity<IdentityUser, IdentityRole>()

And replace ApplicationUser throughout the rest of the project with IdentityUser.