Error when creating roles
See original GitHub issueHi,
I’ve been tinkering with your app, converting it for use in a prerendering / universal app, and it’s taught me a lot thank you! For the most part I had no issues other than you’d expect with things like ngx-datatable which I had to replace with normal bootstrap styled tables.
There is a problem that I cant solve though, I thought it may just be me, so I downloaded a fresh copy of the master and tested, turns out it’s a bug.
To reproduce, login as admin > go to settings > Role Managment > new Role > Complete form (I used all permissions).
The error is :
error Cannot create an instance of abstract type System.Collections.Generic.ICollection
1[Microsoft.AspNetCore.Identity.IdentityUserRole
1[System.String]]. Parameter name: type
No doubt because of having to add the navigation properties for .net core 2.0, which had me running in circles until I saw you’d got it working.
I added break points and it seems to be when the Mapper is fired in the account controller>CreateRole method:
ApplicationRole appRole = Mapper.Map<ApplicationRole>(role);
I’m not really sure how to fix it, I did think of mapping it manually, so it would behave more like the DbInitializer role creation, but that option seems to be quite messy.
Again thank you for the time you took to make this, hopefully one day I can implement the things I’ve learned tinkering and actually make some money 🥇
EDIT: I went ahead and done it manually whilst waiting to see if a fix is forthcoming. I replaced the mapper with:
ApplicationRole appRole = new ApplicationRole()
{
Name = role.Name,
Description = role.Description
};
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Is 's worked correctly
@CybrZr00 Shoot I was not correct. I had been trying so many different things to try to correct the error and when it started working I figured the change I had made to the ApplicationDbContext must have been the fix. I reverted back to an original copy and modified this:
public virtual ICollection<IdentityUserRole<string>> Users { get; set; }
public virtual ICollection<IdentityRoleClaim<string>> Claims { get; set; }
To be this:public virtual List<IdentityUserRole<string>> Users { get; set; }
public virtual List<IdentityRoleClaim<string>> Claims { get; set; }
Sorry for the incorrect piece but this is working well for me now.