c# - 参数类型不能分配给参数类型,尽管它继承

标签 c# asp.net asp.net-mvc-5 dbcontext asp.net-identity-2

我尝试从头开始使用 ASP.net Identity 编写 MVC 应用程序。 为此,我遵循了 Ben Foster 的两个教程(Tutorial Part1Tutorial Part2)

但我停留在第二个教程 - 配置 UserManager。以下行对我不起作用:

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

Visual Studio 下划线

new AppDbContext()

并向我显示以下消息:

Argument type "MyProject.DbContext.AppDbContext" is not assignable to parameter type "System.Data.Entity.DbContext"

我不明白为什么它在我的解决方案中不起作用,因为我完全遵循了教程。我的 AppDbContext 看起来像:

namespace MyProject.DbContext
{
    using MyProject.Models;

    using Microsoft.AspNet.Identity.EntityFramework;

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

我的用户类:

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

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

我还从 Ben 下载了源代码并尝试运行它,它没有任何问题。我认为我的所有文件都不在同一个文件夹中没有任何区别?!

我希望你能帮助我。如果一个简单的教程不能正常工作,那真的很令人沮丧......

问候,winklerrr

最佳答案

我通过删除所有与 owin 和 ASP.net Identity 有关的引用并重新添加它们来解决问题。

我认为,问题是由引用的 dll 和实际使用的 dll 之间的差异引起的...(在包管理器控制台上玩了很多。)

关于c# - 参数类型不能分配给参数类型,尽管它继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25832464/

相关文章:

c# - 类似于控制台的控件,允许完全控制单个文本格式

c# - LINQ:根据重量/大小将列表分成几组

asp.net-mvc - 在 MVC 5 中添加路由

entity-framework - 术语 'update-database' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。查看

asp.net-mvc - 带有 ASP.Net Identity 的 ASP.NET MVC5 中的自定义验证和角色提供者

c# - 如何在控制台应用程序中创建表单后隐藏控制台

c# - 数据库首次迁移 EF Core

c# - 使用 SOAP Web 服务

c# - 如何使用 html 按钮在 asp.net 中注销?

asp.net - 如何将所有 httpErrors 重定向到自定义 url?