Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager` while attempting to activate...












34















I'm getting this error in Login Controller.




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]' while attempting to activate 'Automobile.Server.Controllers.AuthController'.




here is Auth Controller constructor:



private SignInManager<Automobile.Models.Account> _signManager;
private UserManager<Automobile.Models.Account> _userManager;

public AuthController(UserManager<Models.Account> userManager,
SignInManager<Automobile.Models.Account> signManager)
{
this._userManager = userManager;
this._signManager = signManager;
}


and here is ConfigureServices in startup.cs:



public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.Configure<AppConfig>(Configuration.GetSection("AppSettings"));

//var provider = HttpContext.ApplicationServices;
//var someService = provider.GetService(typeof(ISomeService));


services.AddDbContext<Providers.Database.EFProvider.DataContext>(options => options
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("Automobile.Server")
));


services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();
//services.AddScoped<SignInManager<Automobile.Models.Account>, SignInManager<Automobile.Models.Account>>();
//services.AddScoped<UserManager<Automobile.Models.Account>, UserManager<Automobile.Models.Account>>();

services.AddMvc();
App.Service = services.BuildServiceProvider();

// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();

services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.CookieHttpOnly = true;
});

}









share|improve this question




















  • 13





    It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

    – Federico Dipuma
    Jun 11 '17 at 12:01











  • @FedericoDipuma Thank you so much :) Solved.

    – OMID
    Jun 11 '17 at 12:11











  • How did you solved it.. ?

    – Rafael
    Jul 31 '17 at 15:31






  • 3





    @Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

    – OMID
    Aug 12 '17 at 7:52






  • 1





    @OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

    – Null Pointer
    Dec 11 '17 at 10:04
















34















I'm getting this error in Login Controller.




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]' while attempting to activate 'Automobile.Server.Controllers.AuthController'.




here is Auth Controller constructor:



private SignInManager<Automobile.Models.Account> _signManager;
private UserManager<Automobile.Models.Account> _userManager;

public AuthController(UserManager<Models.Account> userManager,
SignInManager<Automobile.Models.Account> signManager)
{
this._userManager = userManager;
this._signManager = signManager;
}


and here is ConfigureServices in startup.cs:



public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.Configure<AppConfig>(Configuration.GetSection("AppSettings"));

//var provider = HttpContext.ApplicationServices;
//var someService = provider.GetService(typeof(ISomeService));


services.AddDbContext<Providers.Database.EFProvider.DataContext>(options => options
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("Automobile.Server")
));


services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();
//services.AddScoped<SignInManager<Automobile.Models.Account>, SignInManager<Automobile.Models.Account>>();
//services.AddScoped<UserManager<Automobile.Models.Account>, UserManager<Automobile.Models.Account>>();

services.AddMvc();
App.Service = services.BuildServiceProvider();

// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();

services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.CookieHttpOnly = true;
});

}









share|improve this question




















  • 13





    It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

    – Federico Dipuma
    Jun 11 '17 at 12:01











  • @FedericoDipuma Thank you so much :) Solved.

    – OMID
    Jun 11 '17 at 12:11











  • How did you solved it.. ?

    – Rafael
    Jul 31 '17 at 15:31






  • 3





    @Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

    – OMID
    Aug 12 '17 at 7:52






  • 1





    @OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

    – Null Pointer
    Dec 11 '17 at 10:04














34












34








34


6






I'm getting this error in Login Controller.




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]' while attempting to activate 'Automobile.Server.Controllers.AuthController'.




here is Auth Controller constructor:



private SignInManager<Automobile.Models.Account> _signManager;
private UserManager<Automobile.Models.Account> _userManager;

public AuthController(UserManager<Models.Account> userManager,
SignInManager<Automobile.Models.Account> signManager)
{
this._userManager = userManager;
this._signManager = signManager;
}


and here is ConfigureServices in startup.cs:



public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.Configure<AppConfig>(Configuration.GetSection("AppSettings"));

//var provider = HttpContext.ApplicationServices;
//var someService = provider.GetService(typeof(ISomeService));


services.AddDbContext<Providers.Database.EFProvider.DataContext>(options => options
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("Automobile.Server")
));


services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();
//services.AddScoped<SignInManager<Automobile.Models.Account>, SignInManager<Automobile.Models.Account>>();
//services.AddScoped<UserManager<Automobile.Models.Account>, UserManager<Automobile.Models.Account>>();

services.AddMvc();
App.Service = services.BuildServiceProvider();

// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();

services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.CookieHttpOnly = true;
});

}









share|improve this question
















I'm getting this error in Login Controller.




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]' while attempting to activate 'Automobile.Server.Controllers.AuthController'.




here is Auth Controller constructor:



private SignInManager<Automobile.Models.Account> _signManager;
private UserManager<Automobile.Models.Account> _userManager;

public AuthController(UserManager<Models.Account> userManager,
SignInManager<Automobile.Models.Account> signManager)
{
this._userManager = userManager;
this._signManager = signManager;
}


and here is ConfigureServices in startup.cs:



public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.Configure<AppConfig>(Configuration.GetSection("AppSettings"));

//var provider = HttpContext.ApplicationServices;
//var someService = provider.GetService(typeof(ISomeService));


services.AddDbContext<Providers.Database.EFProvider.DataContext>(options => options
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("Automobile.Server")
));


services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();
//services.AddScoped<SignInManager<Automobile.Models.Account>, SignInManager<Automobile.Models.Account>>();
//services.AddScoped<UserManager<Automobile.Models.Account>, UserManager<Automobile.Models.Account>>();

services.AddMvc();
App.Service = services.BuildServiceProvider();

// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();

services.AddSession(options =>
{
// Set a short timeout for easy testing.
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.CookieHttpOnly = true;
});

}






c# asp.net asp.net-mvc asp.net-core asp.net-core-identity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 11 '17 at 12:02







OMID

















asked Jun 11 '17 at 11:57









OMIDOMID

4061719




4061719








  • 13





    It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

    – Federico Dipuma
    Jun 11 '17 at 12:01











  • @FedericoDipuma Thank you so much :) Solved.

    – OMID
    Jun 11 '17 at 12:11











  • How did you solved it.. ?

    – Rafael
    Jul 31 '17 at 15:31






  • 3





    @Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

    – OMID
    Aug 12 '17 at 7:52






  • 1





    @OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

    – Null Pointer
    Dec 11 '17 at 10:04














  • 13





    It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

    – Federico Dipuma
    Jun 11 '17 at 12:01











  • @FedericoDipuma Thank you so much :) Solved.

    – OMID
    Jun 11 '17 at 12:11











  • How did you solved it.. ?

    – Rafael
    Jul 31 '17 at 15:31






  • 3





    @Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

    – OMID
    Aug 12 '17 at 7:52






  • 1





    @OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

    – Null Pointer
    Dec 11 '17 at 10:04








13




13





It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

– Federico Dipuma
Jun 11 '17 at 12:01





It seems to me that you are registering IdentityUser as basic user class but then you are using Automobile.Models.Account, which, of course, is not registered anywhere by ASP.NET Identity

– Federico Dipuma
Jun 11 '17 at 12:01













@FedericoDipuma Thank you so much :) Solved.

– OMID
Jun 11 '17 at 12:11





@FedericoDipuma Thank you so much :) Solved.

– OMID
Jun 11 '17 at 12:11













How did you solved it.. ?

– Rafael
Jul 31 '17 at 15:31





How did you solved it.. ?

– Rafael
Jul 31 '17 at 15:31




3




3





@Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

– OMID
Aug 12 '17 at 7:52





@Lobato in services.AddIdentity just replace IdentityUser with your Identity User class

– OMID
Aug 12 '17 at 7:52




1




1





@OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

– Null Pointer
Dec 11 '17 at 10:04





@OMID why don't you post your comment as answer, this saved me but after some serious headache of RnD..

– Null Pointer
Dec 11 '17 at 10:04












2 Answers
2






active

oldest

votes


















37














You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.



So, change



services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();


to



services.AddIdentity<Automobile.Models.Account, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();





share|improve this answer



















  • 2





    I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

    – devC
    Jan 7 '18 at 16:30











  • post your code please.

    – HojjatK
    Jan 8 '18 at 12:59











  • Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

    – devC
    Jan 9 '18 at 4:20











  • stackoverflow.com/questions/48161467/…

    – devC
    Jan 9 '18 at 4:31











  • seems your connection string has been not set correctly, check out my answer in your post.

    – HojjatK
    Jan 11 '18 at 11:17





















25














Just to be clear about the answer:



If you use the class ApplicationUser in startup.cs: services.AddIdentity<ApplicationUser, IdentityRole>()



then you must use the same class in your controller when injecting it:



public AccountController(UserManager<ApplicationUser> userManager)


If you use some other class such as:



public AccountController(UserManager<IdentityUser> userManager)


then you will get this error:




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[IdentityUser]'




because you used ApplicationUser in startup, not IdentityUser so this type is not registered with the injection system.






share|improve this answer





















  • 4





    This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

    – Johan Herstad
    Jun 4 '18 at 7:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44483589%2funable-to-resolve-service-for-type-microsoft-aspnetcore-identity-usermanager-w%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









37














You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.



So, change



services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();


to



services.AddIdentity<Automobile.Models.Account, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();





share|improve this answer



















  • 2





    I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

    – devC
    Jan 7 '18 at 16:30











  • post your code please.

    – HojjatK
    Jan 8 '18 at 12:59











  • Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

    – devC
    Jan 9 '18 at 4:20











  • stackoverflow.com/questions/48161467/…

    – devC
    Jan 9 '18 at 4:31











  • seems your connection string has been not set correctly, check out my answer in your post.

    – HojjatK
    Jan 11 '18 at 11:17


















37














You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.



So, change



services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();


to



services.AddIdentity<Automobile.Models.Account, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();





share|improve this answer



















  • 2





    I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

    – devC
    Jan 7 '18 at 16:30











  • post your code please.

    – HojjatK
    Jan 8 '18 at 12:59











  • Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

    – devC
    Jan 9 '18 at 4:20











  • stackoverflow.com/questions/48161467/…

    – devC
    Jan 9 '18 at 4:31











  • seems your connection string has been not set correctly, check out my answer in your post.

    – HojjatK
    Jan 11 '18 at 11:17
















37












37








37







You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.



So, change



services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();


to



services.AddIdentity<Automobile.Models.Account, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();





share|improve this answer













You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.



So, change



services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();


to



services.AddIdentity<Automobile.Models.Account, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = false;
})
.AddEntityFrameworkStores<Providers.Database.EFProvider.DataContext>()
.AddDefaultTokenProviders();






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 '18 at 9:32









HojjatKHojjatK

48167




48167








  • 2





    I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

    – devC
    Jan 7 '18 at 16:30











  • post your code please.

    – HojjatK
    Jan 8 '18 at 12:59











  • Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

    – devC
    Jan 9 '18 at 4:20











  • stackoverflow.com/questions/48161467/…

    – devC
    Jan 9 '18 at 4:31











  • seems your connection string has been not set correctly, check out my answer in your post.

    – HojjatK
    Jan 11 '18 at 11:17
















  • 2





    I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

    – devC
    Jan 7 '18 at 16:30











  • post your code please.

    – HojjatK
    Jan 8 '18 at 12:59











  • Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

    – devC
    Jan 9 '18 at 4:20











  • stackoverflow.com/questions/48161467/…

    – devC
    Jan 9 '18 at 4:31











  • seems your connection string has been not set correctly, check out my answer in your post.

    – HojjatK
    Jan 11 '18 at 11:17










2




2





I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

– devC
Jan 7 '18 at 16:30





I have the similar problem, I have my customer user and role defined in the AddIdentity method and I'm still getting the same error. Any idea why? I could post my code in a separate thread.

– devC
Jan 7 '18 at 16:30













post your code please.

– HojjatK
Jan 8 '18 at 12:59





post your code please.

– HojjatK
Jan 8 '18 at 12:59













Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

– devC
Jan 9 '18 at 4:20





Actually, I resolved that issue, but now facing a problem with creating the DB connection. I'll post the problem.

– devC
Jan 9 '18 at 4:20













stackoverflow.com/questions/48161467/…

– devC
Jan 9 '18 at 4:31





stackoverflow.com/questions/48161467/…

– devC
Jan 9 '18 at 4:31













seems your connection string has been not set correctly, check out my answer in your post.

– HojjatK
Jan 11 '18 at 11:17







seems your connection string has been not set correctly, check out my answer in your post.

– HojjatK
Jan 11 '18 at 11:17















25














Just to be clear about the answer:



If you use the class ApplicationUser in startup.cs: services.AddIdentity<ApplicationUser, IdentityRole>()



then you must use the same class in your controller when injecting it:



public AccountController(UserManager<ApplicationUser> userManager)


If you use some other class such as:



public AccountController(UserManager<IdentityUser> userManager)


then you will get this error:




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[IdentityUser]'




because you used ApplicationUser in startup, not IdentityUser so this type is not registered with the injection system.






share|improve this answer





















  • 4





    This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

    – Johan Herstad
    Jun 4 '18 at 7:02
















25














Just to be clear about the answer:



If you use the class ApplicationUser in startup.cs: services.AddIdentity<ApplicationUser, IdentityRole>()



then you must use the same class in your controller when injecting it:



public AccountController(UserManager<ApplicationUser> userManager)


If you use some other class such as:



public AccountController(UserManager<IdentityUser> userManager)


then you will get this error:




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[IdentityUser]'




because you used ApplicationUser in startup, not IdentityUser so this type is not registered with the injection system.






share|improve this answer





















  • 4





    This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

    – Johan Herstad
    Jun 4 '18 at 7:02














25












25








25







Just to be clear about the answer:



If you use the class ApplicationUser in startup.cs: services.AddIdentity<ApplicationUser, IdentityRole>()



then you must use the same class in your controller when injecting it:



public AccountController(UserManager<ApplicationUser> userManager)


If you use some other class such as:



public AccountController(UserManager<IdentityUser> userManager)


then you will get this error:




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[IdentityUser]'




because you used ApplicationUser in startup, not IdentityUser so this type is not registered with the injection system.






share|improve this answer















Just to be clear about the answer:



If you use the class ApplicationUser in startup.cs: services.AddIdentity<ApplicationUser, IdentityRole>()



then you must use the same class in your controller when injecting it:



public AccountController(UserManager<ApplicationUser> userManager)


If you use some other class such as:



public AccountController(UserManager<IdentityUser> userManager)


then you will get this error:




InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[IdentityUser]'




because you used ApplicationUser in startup, not IdentityUser so this type is not registered with the injection system.







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 24 '18 at 3:46









Erik Philips

41.1k691124




41.1k691124










answered Feb 3 '18 at 14:45









Greg GumGreg Gum

11.3k1780133




11.3k1780133








  • 4





    This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

    – Johan Herstad
    Jun 4 '18 at 7:02














  • 4





    This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

    – Johan Herstad
    Jun 4 '18 at 7:02








4




4





This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

– Johan Herstad
Jun 4 '18 at 7:02





This counts for all references, so if you implement the new Razor identity for asp.net core 2.1 to replace your old identitysystem, you need to replace their automatic implementation of stuff like SignInManager<IdentityUser> to SignInManager<ApplicationUser> wherever it is used. This can be annoying. Also you need to re-route from normal /Account/Login to /Identity/Account/Login etc. just some tips to help ;)

– Johan Herstad
Jun 4 '18 at 7:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44483589%2funable-to-resolve-service-for-type-microsoft-aspnetcore-identity-usermanager-w%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Futebolista

Feedback on college project

Albești (Vaslui)