No service for type 'Microsoft.AspNetCore.Identity.SignInManager When

Dani picture Dani · Aug 25, 2016 · Viewed 20.9k times · Source

I am getting

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.SignInManager 1[Authorization.IdentityModels.ApplicationUser]' has been registered.

when I run my ApsCore MVC website.

this are segments from my code:

ConfigureServices:

services.AddDbContext<ApplicationDbContext>(options =>
                        options.UseNpgsql(configuration["Data:DefaultConnection:ConnectionString"]));



services.AddIdentity<ApplicationUser, IdentityRole<Guid>>()
                    .AddEntityFrameworkStores<ApplicationDbContext, Guid>()
                    .AddDefaultTokenProviders();

Configure:

app.UseIdentity();

ApplicationDbContext.cs

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid> 

ApplicationUser.cs

 public class ApplicationUser : IdentityUser<Guid>

I will be very happy if you can help me.

Answer

Nozim Turakulov picture Nozim Turakulov · Oct 15, 2018

Faced with the same issue after moving my Identity classes to Guid and found solution here:

You probably need to change your login partial view to use the new user type IdentityUser

Within Views/Shared/_LoginPartial.cshtml, I just changed

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

To

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

and that worked for me.