The argument type is not assigned to the parameter type although it inherits

I tried to write an ASP.net id MVC application from scratch. For this I followed two tutorials from Ben Foster ( Tutorial Part1 and Tutorial Part2 )

But I am stuck with the second tutorial - Configuring UserManager. The following line doesn't work for me:

    // configure the user manager
    UserManagerFactory = () =>
    {
        var usermanager = new UserManager<AppUser>(
            new UserStore<AppUser>(new AppDbContext()));
        ...
    }

      

Visual Studio highlights

new AppDbContext()

      

and will show me the following message:

The argument type "MyProject.DbContext.AppDbContext" is not assigned to the parameter type "System.Data.Entity.DbContext"

I don't understand why this doesn't work in my solution because I followed the tutorial completely. My AppDbContext looks like this:

namespace MyProject.DbContext
{
    using MyProject.Models;

    using Microsoft.AspNet.Identity.EntityFramework;

    public class AppDbContext : IdentityDbContext<User>
    {
        public AppDbContext()
            : base("DefaultConnection")
        {
        }
    }
}

      

My user class:

namespace MyProject.Models
{
    using Microsoft.AspNet.Identity.EntityFramework;

    public class User : IdentityUser
    {
        public string Name{ get; set; }
    }
}

      

I also downloaded the source code from Ben and tried to run it and it works without issue. I guess it doesn't matter that all my files are not in the same folder ?!

Hope you can help me. It's really frustrating if a simple tutorial doesn't work as it should ...

Regards, winklerrr

+3


source to share


2 answers


I solved the problem by removing all links that had something to do with owin and ASP.net Idendity and read them again.



I think the problem was caused by a mismatch between the referenced dlls and the actual dlls used ... (Played with the Package Manager Console.)

+1


source


Yours UserManager

accepts AppUser

as a generic type: UserManager<AppUser>

when db-context accepts User

as a generic parameter. AppUser

and User

are not the same classes.



Your user-defining class should be the same everywhere.

0


source







All Articles