ASP.NET : ROLES : There is no argument given that corresponds to the required formal parameter

  Uncategorised

I’ve just started learning about asp.net and it’s identity features.

And I have a simple problem of:

Error CS7036 There is no argument given that corresponds to the
required formal parameter ‘roleManager’ of
‘EventContext.SeedAsync(UserManager,
RoleManager)’ ProjektuppgiftASP.NET D:PROGRAMMERINGVS
CODEASPProjektASPProjektProjektuppgiftASP.NETPagesIndex.cshtml.cs 39 Active

Here is my Context code:

namespace ProjektuppgiftASP.NET.Data
{ 
    public class EventContext : IdentityDbContext<MyUser>
    {
        public EventContext(DbContextOptions<EventContext> options)
            : base(options)
        {
        }
        public DbSet<Event> Event { get; set; }
        public DbSet<MyUser> MyUser { get; set; }
        public async Task SeedAsync(UserManager<MyUser> userManager, RoleManager<IdentityRole> roleManager)
        {
            await Database.EnsureDeletedAsync();
            await Database.EnsureCreatedAsync();

            

            MyUser user = new MyUser()
            {
                UserName = "Administrator",
            };
            await userManager.CreateAsync(user, "Admin_1");

            await roleManager.CreateAsync(new IdentityRole("admin"));
            await userManager.AddToRoleAsync(user, "admin");

            

            Event[] Event = new Event[]
            {
                new Event() { Title="Alicia Keys", Description="Music", Place="Ericsson Globe", Adress="Stockholm", Date=DateTime.Now,  SpotsAvailable=150,  },
                 new Event() { Title="CS:Go Major", Description="E-sport", Place="Ericsson Globe", Adress="Stockholm", Date=DateTime.Now,  SpotsAvailable=100,  },
                  new Event() { Title="Sweden International Horse Show", Description="Horse show", Place="Ericsson Globe", Adress="Stockholm", Date=DateTime.Now,  SpotsAvailable=330,  },
                   new Event() { Title="GAIS - Ă–ster IF", Description="Soccer", Place="Ullevi", Adress="Gothenburg",Date=DateTime.Now,  SpotsAvailable=270, },
                    new Event() { Title="Iron Maiden", Description="Music", Place="Ullevi", Adress="Gothenburg", Date=DateTime.Now,  SpotsAvailable=500, }
            };



            await AddRangeAsync(Event);

            await SaveChangesAsync();
        }
    }
   
}

And here is my index.cshtml.cs

namespace ProjektuppgiftASP.NET.Pages
{
    public class IndexModel : PageModel
    {
        private readonly ILogger<IndexModel> _logger;
        private readonly EventContext _context;
        private readonly UserManager<MyUser> _userManager;
        private readonly RoleManager<IdentityRole> _roleManager;


        public IndexModel(ILogger<IndexModel> logger, 
            EventContext context, 
            UserManager<MyUser> userManager,
            RoleManager<IdentityRole> roleManager)
        {
            _logger = logger;
            _context = context;
            _userManager = userManager;
            _roleManager = roleManager;
        }

       public async Task OnGetAsync()
        {
            await _context.SeedAsync(_userManager);
        }
    }
}

Source: Visual Studio Questions

LEAVE A COMMENT