.net 从IdentityServer 4升级到邓迪6.2后崩溃-序列包含多个元素

5us2dqdw  于 2023-01-06  发布在  .NET
关注(0)|答案(1)|浏览(92)

我正在将一个现有项目从**. Net Core 2.2**&IdentityServer4 2.4升级到**. Net 7Duende 6.2.0**。我通过升级到IdentityServer4 3.0,然后升级到4.0,并在PersistedGrantDbContextConfigurationDbContext上使用IdentityServer4的每个主要版本运行迁移,以增量方式执行此更新。
在我迁移到IdentityServer4v4之后,我又迁移到Duende6.2,并最后一次重新运行迁移。
在调用connect/token端点时,出现以下异常:

System.InvalidOperationException: Sequence contains more than one element.
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Identity.UserManager`1.FindByEmailAsync(String email)
   at Microsoft.AspNetCore.Identity.UserValidator`1.ValidateEmail(UserManager`1 manager, TUser user, List`1 errors)
   at Microsoft.AspNetCore.Identity.UserValidator`1.ValidateAsync(UserManager`1 manager, TUser user)
   at Microsoft.AspNetCore.Identity.UserManager`1.ValidateUserAsync(TUser user)
   at Microsoft.AspNetCore.Identity.UserManager`1.UpdateUserAsync(TUser user)
   at Microsoft.AspNetCore.Identity.UserManager`1.CheckPasswordAsync(TUser user, String password)
   at Microsoft.AspNetCore.Identity.SignInManager`1.CheckPasswordSignInAsync(TUser user, String password, Boolean lockoutOnFailure)
   at Duende.IdentityServer.AspNetIdentity.ResourceOwnerPasswordValidator`1.ValidateAsync(ResourceOwnerPasswordValidationContext context) in /_/src/AspNetIdentity/ResourceOwnerPasswordValidator.cs:line 52
   at Duende.IdentityServer.Validation.TokenRequestValidator.ValidateResourceOwnerCredentialRequestAsync(NameValueCollection parameters) in /_/src/IdentityServer/Validation/Default/TokenRequestValidator.cs:line 500
   at Duende.IdentityServer.Validation.TokenRequestValidator.RunValidationAsync(Func`2 validationFunc, NameValueCollection parameters) in /_/src/IdentityServer/Validation/Default/TokenRequestValidator.cs:line 189
   at Duende.IdentityServer.Validation.TokenRequestValidator.ValidateRequestAsync(NameValueCollection parameters, ClientSecretValidationResult clientValidationResult) in /_/src/IdentityServer/Validation/Default/TokenRequestValidator.cs:line 174
   at Duende.IdentityServer.Endpoints.TokenEndpoint.ProcessTokenRequestAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/TokenEndpoint.cs:line 98
   at Duende.IdentityServer.Endpoints.TokenEndpoint.ProcessAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/TokenEndpoint.cs:line 75
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IdentityServerOptions options, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in /_/src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 101
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IdentityServerOptions options, IEndpointRouter router, IUserSession userSession, IEventService events, IIssuerNameService issuerNameService, ISessionCoordinationService sessionCoordinationService) in /_/src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 117
   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in /_/src/IdentityServer/Hosting/MutualTlsEndpointMiddleware.cs:line 94
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes/DynamicSchemeAuthenticationMiddleware.cs:line 47
   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 27
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
    • 启动. cs**
services.AddIdentityServer()
         .AddConfigurationStore(options =>
         {
            options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
         })
         .AddOperationalStore(options =>
         {
             options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));

             options.EnableTokenCleanup = true;
             options.TokenCleanupInterval = 30;
         })
         .AddInMemoryApiScopes(IdentityServerConfig.GetApiScopes())
         .AddAspNetIdentity<ApplicationUser>()
         .AddExtensionGrantValidator<TokenGrantValidator>()
         .AddProfileService<ProfileService>();

相关软件包

<PackageReference Include="Duende.IdentityServer" Version="6.2.0" />
    <PackageReference Include="Duende.IdentityServer.AspNetIdentity" Version="6.2.0" />
    <PackageReference Include="Duende.IdentityServer.EntityFramework" Version="6.2.0" />
    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
  
    <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="7.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />

在另一个参考项目中

<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
    <PackageReference Include="NLog" Version="5.1.0" />
    <PackageReference Include="SqlBulkTools.NetStandard" Version="2.1.30" />
    <PackageReference Include="StackExchange.Redis" Version="2.1.30" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />

我理解错误Sequence contains more than one element,但是由于这个异常发生在中间件中,我不确定如何解决这个问题。

问题

如何调试/排除SDK或中间件中发生的异常?

nom7f22z

nom7f22z1#

从堆栈跟踪来看,这个方法似乎就是给您带来麻烦的方法:

at Microsoft.AspNetCore.Identity.UserManager`1.FindByEmailAsync(String email)

我会检查数据库,并检查您是否有多个用户使用相同的电子邮件。

相关问题