Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll

时间:2019-07-10 11:25:59

标签: c# visual-studio-2019

我正在尝试制作.NET核心Web应用程序,当我构建解决方案时,出现以下错误提示,请帮帮我。

它还显示有关程序包兼容性的错误 这一切都是在我更新图书馆后发生的

我尝试更改csproj文件中的版本号,但是 它会产生更多错误 帮我解决这个问题

输出标签中的错误

Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll
An exception of type 'System.InvalidOperationException' occurred in Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll but was not handled in user code
AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>.

Startup.cs文件

{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddDbContext<MyContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
            services.AddIdentity<Customer, ApplicationRole>()
                .AddEntityFrameworkStores<MyContext>()
                .AddDefaultTokenProviders();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseIdentity();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                //Admin area routes
                routes.MapRoute(
                    name: "AdminAreaRoute",
                    template: "{area:exists}/{controller=Products}/{action=Index}/{id?}");
            });
        }
    }
}

我也收到此错误

1>D:\Projects\Ghost- depricated\Ghost\Ghost.csproj : warning NU1701: Package 'EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.
1>D:\Projects\Ghost- depricated\Ghost\Ghost.csproj : warning NU1701: Package 'Microsoft.AspNet.Identity.AspNetCoreCompat 0.3.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.
1>D:\Projects\Ghost- depricated\Ghost\Ghost.csproj : warning NU1701: Package 'Microsoft.AspNet.Identity.Core 2.2.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.
1>D:\Projects\Ghost- depricated\Ghost\Ghost.csproj : warning NU1701: Package 'Microsoft.AspNet.Identity.EntityFramework 2.2.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.

1 个答案:

答案 0 :(得分:1)

尝试卸载EntityFramework 6.2.0,然后安装Microsoft.EntityFrameworkCore软件包:

在包管理器控制台中执行Install-Package Microsoft.EntityFrameworkCore -Version 2.2.6命令

或 手动安装:

右键单击项目>管理nuget软件包...>浏览选项卡>键入Microsoft.EntityFrameworkCore,然后安装它