簡體   English   中英

Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll 中發生“System.InvalidOperationException”

[英]'System.InvalidOperationException' occurred in Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll

我正在嘗試制作一個 .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.

嘗試卸載EntityFramework 6.2.0然后安裝Microsoft.EntityFrameworkCore包:

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

或手動安裝:

右鍵單擊項目 > 管理 nuget 包... > 瀏覽選項卡 > 鍵入 Microsoft.EntityFrameworkCore 然后安裝它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM