我正在使用 ASP.NET Core MVC 專案和 Microsoft.AspNetCore.Identity v6.0,當我運行添加遷移時它顯示例外
訪問 Microsoft.Extensions.Hosting 服務時出錯。在沒有應用程式服務提供商的情況下繼續。錯誤:無法構造某些服務(驗證服務描述符時出錯“ServiceType:Microsoft.AspNetCore.Identity.ISecurityStampValidator Lifetime:Scoped ImplementationType:Microsoft.AspNetCore.Identity.SecurityStampValidator 1[Microsoft.AspNetCore.Identity.IdentityUser]': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft .AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'。)(驗證服務描述符時出錯'ServiceType: Microsoft.AspNetCore.Identity.ITwoFactorSecurityStampValidator Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.TwoFactorSecurityStampValidator1[Microsoft.AspNetCore.Identity.IdentityUser]': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'。)(驗證服務描述符時出錯'ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory 1[Microsoft.AspNetCore.Identity.IdentityUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2[ Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole]':嘗試激活“Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore 4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.UserManager1 [Microsoft.AspNetCore ] 時無法決議型別“Microsoft.EntityFrameworkCore.DbContext”的服務.Identity.IdentityUser] 生命周期:Scoped ImplementationType:Microsoft.AspNetCore.Identity.UserManager1[Microsoft.AspNetCore.Identity.IdentityUser]': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'。)(驗證服務描述符'ServiceType:Microsoft.AspNetCore.Identity.SignInManager 1[Microsoft.AspNetCore.Identity.IdentityUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.SignInManager1[ Microsoft.AspNetCore.Identity.IdentityUser]':嘗試激活 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore 4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.RoleManager1 [Microsoft.AspNetCore.Identity.IdentityRole]時,無法決議型別 'Microsoft.EntityFrameworkCore.DbContext' 的服務 [Microsoft.AspNetCore.Identity.IdentityRole] ImplementationType:Microsoft.AspNetCore.Identity.RoleManager 1[Microsoft.AspNetCore.Identity.IdentityRole]': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore3[Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'。)(驗證服務描述符“ServiceType:Microsoft.AspNetCore.Identity”時出錯。用戶商店1[Microsoft.AspNetCore.Identity.IdentityUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore4 [Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]':嘗試激活“Microsoft.EntityFrameworkCore.DbContext”時無法決議“Microsoft.EntityFrameworkCore.DbContext”型別的服務。 AspNetCore.Identity.EntityFrameworkCore.UserStore 4[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IRoleStore1[Microsoft.AspNetCore.Identity.IdentityRole] 生命周期:范圍實施型別:Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore 3[Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String]': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore3[Microsoft.AspNetCore.Identity.IdentityRole,Microsoft.EntityFrameworkCore.DbContext,System.String ]'。) 無法創建“DbContext”型別的物件。有關設計時支持的不同模式,請參閱https://go.microsoft.com/fwlink/?linkid=851728
uj5u.com熱心網友回復:
從錯誤來看,您似乎缺少一些依賴項,并且系統無法為某些介面注入正確的實作。Program.cs在課堂上注冊缺失的服務,
您是否添加services.AddDbContext()了正確的連接設定?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/511421.html
標籤:网。网实体框架asp.net 核心
