asp.net-core-mvcasp.net-identityscaffoldingasp.net-mvc-scaffoldingasp.net-core-7.0

Dot Net core MVC 7 Identity Unable to resolve service for type


I am Implementing Identity in Dot Net core MVC 7. This is the tutorial I was Following. Then Suddenly Error Came Error Came

An unhandled exception occurred while processing the request.
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'LearnIdentity.Areas.Identity.Pages.Account.RegisterModel'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)

I tried re-watching video again and again. Tried chat GTP. Unable to relsove please help me Click here for Source code


Solution

  • I download your repo and reproduce the issue in my side when click the login button.

    Error

    enter image description here

    Then I check the Program.cs file and login.cshtml, login.cshtml.cs file. You are using ApplicationUser in Program.cs and using IdentityUser in login.cshtml.cs.

    The solution is using ApplicationUser in login.cshtml.cs. And the issue will be fixed. And please don't forget add using LearnIdentity.Data; in login.cshtml.cs

    enter image description here

    It works in my side

    enter image description here