Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[System.Model.User]' has been registered

Can somebody please help me? I am having trouble running the app after scaffolding Identity. It keeps showing the No service for type "’Microsoft.AspNetCore.Identity.UserManager`1[OAS.Model.User]’ has been registered." exception. I have searched thorugh the Internet and checked the _LoginPartial.cshtml as well. The @inject part is correct but it is still not working. Here are my code files:

_LoginPartial.cshtml:

@using Microsoft.AspNetCore.Identity
@using OAS.Model

@inject SignInManager<User> SignInManager
@inject UserManager<User> UserManager

<ul class="navbar-nav">
@if (SignInManager.IsSignedIn(User))
{
    <li class="nav-item">
        <a id="manage" class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
    </li>
    <li class="nav-item">
        <form id="logoutForm" class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/Index", new { area = "" })">
            <button id="logout" type="submit" class="nav-link btn btn-link text-dark">Logout</button>
        </form>
    </li>
}
else
{
    <li class="nav-item">
        <a class="nav-link text-dark" id="register" asp-area="Identity" asp-page="/Account/Register">Register</a>
    </li>
    <li class="nav-item">
        <a class="nav-link text-dark" id="login" asp-area="Identity" asp-page="/Account/Login">Login</a>
    </li>
}
</ul>

User.cs file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 public class User : IdentityUser
    {
        [Required]
        public string Description { get; set; }
    }

I have no idea what to change next.

>Solution :

looks like you’re trying to use the UserManager, but it has not been registered with the service container.

try this:

services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading