简体   繁体   English

.NET 6 身份自定义 - 错误:没有从 ApplicationUser 到 IdentityUser 的隐式引用转换<string></string>

[英].NET 6 Identity Customization - Error: There is no implicit reference conversion from ApplicationUser to IdentityUser<string>

I have customized all .NET 6 Identity model classes.我已经定制了所有 .NET 6 Identity model 类。 My setup was working just fine for over a year.我的设置工作了一年多。 I updated to the latest .NET core identity libraries (6.0.7) and ran a new DB-Scaffold today, and all of a sudden, I'm getting the following error for ApplicationUser (plus the same error for the remainder of the custom Identity classes):我更新到最新的 .NET 核心身份库(6.0.7)并今天运行了一个新的 DB-Scaffold,突然之间,我收到了 ApplicationUser 的以下错误(加上自定义身份的其余部分的相同错误类):

CS0311 The type 'ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>'. CS0311 类型“ApplicationUser”不能用作泛型类型或方法“IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>”中的类型参数“TUser”。 There is no implicit reference conversion from 'ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'没有从“ApplicationUser”到“Microsoft.AspNetCore.Identity.IdentityUser”的隐式引用转换

I've got the EF database context configured as follows:我已将 EF 数据库上下文配置如下:

public partial class DatabaseContext: IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserClaim, ApplicationUserRole, ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>

My Identity classes are as follows:我的身份类如下:

public partial class ApplicationUser: IdentityUser<string>

public partial class ApplicationRole: IdentityRole<string>

public partial class ApplicationUserClaim: IdentityUserClaim<string>

public partial class ApplicationUserRole: IdentityUserRole<string>

public partial class ApplicationUserLogin: IdentityUserLogin<string>

public partial class ApplicationRoleClaim: IdentityRoleClaim<string>

public partial class ApplicationUserToken: IdentityUserToken<string>

This approach seems to be lined up with what Microsoft recommends here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-6.0这种方法似乎与微软在这里推荐的一致: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-6.0

I've tried everything I can think of but the errors are still coming up (tried changing over to a Guid instead of a string, for example).我已经尝试了我能想到的所有方法,但错误仍然出现(例如,尝试转换为 Guid 而不是字符串)。 I'm at a loss and hoping someone might be able to give me some advice on how to fix these errors?我很茫然,希望有人能给我一些关于如何解决这些错误的建议?

This was due to the fact that I was still configured for the .NET 5 way of using Identity.这是因为我仍然为 .NET 5 使用身份的方式进行了配置。 I created a new .NET 6 MVC project and migrated everything over to it, and that fixed the problem.我创建了一个新的 .NET 6 MVC 项目并将所有内容迁移到它,这解决了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有从ApplicationUser到IdentityUser的隐式引用转换 - There is no implicit reference conversion from ApplicationUser to IdentityUser 没有从 ApplicationUser 到 Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的隐式引用转换 - There is no implicit reference conversion from ApplicationUser to Microsoft.AspNet.Identity.EntityFramework.IdentityUser 没有隐式参考转换错误 - No implicit reference conversion error ASP.net身份:如何获取当前的IdentityUser(ApplicationUser)? UserManager.FindById在哪里? - ASP.net identity: How to get current IdentityUser (ApplicationUser)? Where is UserManager.FindById? Net Core:没有从“实体”到“IEntity”的隐式引用转换 - Net Core: No implicit reference conversion from 'Entities' to 'IEntity' 从ApplicationUser(IdentityUser)继承的类上的级联删除 - Cascade delete on classes inherited from ApplicationUser(IdentityUser) 当我使用 ApplicationUser 而不是 IdentityUser 时,出现此错误“无法解析 AspNetCore.Identity.SignInManager 类型的服务” - I got this error "Unable to resolve service for type AspNetCore.Identity.SignInManager" when I use ApplicationUser instead IdentityUser c#类型推断 - 错误 - 没有隐式引用转换 - c# Type Inference - Error - There is no implicit reference conversion from ASP.NET身份IdentityUser自定义属性导致运行时错误 - Asp.NET Identity IdentityUser Custom Properties Cause Runtime Error 从T和字符串隐式转换 - implicit conversion from T and string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM