Question

I'm trying to add a new role to the ASP.NET Core Identity system. But no luck so far.

Code: C#

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;

private ApplicationDbContext _context;

var roleStore = new RoleStore<IdentityRole>(_context);
var roleManager = new RoleManager<IdentityRole>(roleStore); // <============ Problem
await roleManager.CreateAsync(new IdentityRole("Somevalue"));

Error message:

Error CS7036 There is no argument given that corresponds to the required formal parameter 'roleValidators' of 'RoleManager.RoleManager(IRoleStore, IEnumerable>, ILookupNormalizer, IdentityErrorDescriber, ILogger>, IHttpContextAccessor)'

Same code in .net 4.6 VB.net works

    Dim roleManager = New RoleManager(Of IdentityRole)(New RoleStore(Of IdentityRole))
    Dim newRoleName As String = "Some groupname"

    If Not roleManager.RoleExists(newRoleName) Then

        Dim role = New IdentityRole()

        role.Name = newRoleName
        roleManager.Create(role)

    End If
1
0
8/31/2016 8:03:01 AM

Popular Answer

It seems you try to use aspnet identity without dependency injection. See official docs how to configure identity with aspnet core.

0
8/31/2016 8:34:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow