Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Identity Manager Error: error when trying to create a controller of type 'MetaController' (no parameterless public constructor)

I got ThinkTecture's IdentityManager running, but now when going to the '/idm/ url I get an error:

An error occurred when trying to create a controller of type 'MetaController'. Make sure that the controller has a parameterless public constructor.

The error was mentioned in a comment in another StackOverflow issue but a solution to this issue was not given. enter image description here

like image 307
Bart Avatar asked Feb 09 '23 17:02

Bart


2 Answers

While formulating this question I also found the solution in an issue of the IdentityManager GitHub repo. I had to change the constructor for ApplicationUserManager in IdentityConfig.cs from:

public ApplicationUserManager(IUserStore<ApplicationUser> store): base(store) {}

to:

public ApplicationUserManager(ApplicationUserStore store): base(store) {}

And a similar type change in the Create function just below that to get everything compiling.

The ApplicationUserStore should be defined as follows.

public class ApplicationUserStore: UserStore<ApplicationUser>
{
    public ApplicationUserStore(ApplicationDbContext ctx): base(ctx) {}
}

I put it in Startup.cs just above the declaration of ApplicationRoleStore.

like image 79
Bart Avatar answered Feb 11 '23 07:02

Bart


I had the same problem, but instead of modifying constructors, I fixed it by tweaking the DI registration

    public static void ConfigureMyCustomIdentityManagerService(this IdentityManagerServiceFactory factory, string connectionString)
    {
        factory.Register(new Registration<UserManager<User, Guid>>(x => new MyCustomUserManager(new MsSqlUserStore<User>(connectionString))));
        factory.Register(new Registration<RoleManager<Role, Guid>>(x => new RoleManager<Role, Guid>(new MsSqlRoleStore<Role>(connectionString))));

        factory.IdentityManagerService = new Registration<IIdentityManagerService, AspNetIdentityManagerService<User, Guid, Role, Guid>>();
    }
like image 44
spatialguy Avatar answered Feb 11 '23 06:02

spatialguy