Reputation: 31
I am getting the following error when I try to call AddDefaultIdentity
in an ASP.NET WebAPI project:
'IServiceCollection' does not contain a definition for 'AddDefaultIdentity' and no accessible extension method 'AddDefaultIdentity' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Upvotes: 3
Views: 6831
Reputation: 12725
'IServiceCollection' does not contain a definition for 'AddDefaultIdentity' and no accessible extension method 'AddDefaultIdentity' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
I reproduced the issue when I installed Microsoft.AspNetCore.Identity.UI
package higher than version 3.0 in a 3.0 project. Note: AddDefaultIdentity
extension method is used to add the default UI service for Razor Pages and MVC.
You could use AddIdentity
instead of AddDefaultIdentity
like below:
services.AddIdentity<ApplicationUser,IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
If you want to use AddDefaultIdentity
, you should update the version of Microsoft.AspNetCore.Identity.UI
to 3.0.
For the difference between AddDefaultIdentity and AddIdentity , refer to https://medium.com/@xsoheilalizadeh/asp-net-core-identity-deep-dive-stores-e0e54291b51d
Upvotes: 9