How to fix 'InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager

This post show you how to solve 'InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager [Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.' when custom ASP.NET Identity.

For example if you create a custom user class as shown below.

public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

You need to open the _LoginPartial.cshtml file

@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager

Next, change to

@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager

You also need to open all related files and then change IdentityUser to ApplicationUser.