When multiple users set the same email, editing role information will be wrong
See original GitHub issueDescribe the bug
When multiple users set the same email, editing role information will throw an exception.
To Reproduce
When multiple users set the same email
Add role to one of the users
This situation seems to be caused by the use of email information to query users within the framework
After thinking about it, we found that in the admin panel, we can’t set up two roles of the same email, but in the STS.Identity In, we can change our email information to an existing email
Relevant parts of the log file
System.InvalidOperationException: Sequence contains more than one element
at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable
1 source)
at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore9.FindByEmailAsync(String normalizedEmail, CancellationToken cancellationToken) at Microsoft.AspNetCore.Identity.UserManager
1.FindByEmailAsync(String email)
at Microsoft.AspNetCore.Identity.UserValidator1.ValidateEmail(UserManager
1 manager, TUser user, List1 errors) at Microsoft.AspNetCore.Identity.UserValidator
1.ValidateAsync(UserManager1 manager, TUser user) at Microsoft.AspNetCore.Identity.UserManager
1.ValidateUserAsync(TUser user)
at Microsoft.AspNetCore.Identity.UserManager1.UpdateUserAsync(TUser user) at Microsoft.AspNetCore.Identity.UserManager
1.AddToRoleAsync(TUser user, String role)
at Skoruba.IdentityServer4.Admin.EntityFramework.Identity.Repositories.IdentityRepository11.CreateUserRoleAsync(String userId, String roleId) at Skoruba.IdentityServer4.Admin.BusinessLogic.Identity.Services.IdentityService
22.CreateUserRoleAsync(TUserRolesDto role)
at CPDIS.IdentityServer.Admin.Controllers.IdentityController22.UserRoles(TUserRolesDto role) in E:\DevWork\OutSource\CPDIS\CPDIS.IdentityServer\src\CPDIS.IdentityServer.Admin\Controllers\IdentityController.cs:line 195 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask
1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.CspMiddleware.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Use username.
And I modified the settings of StartupHelpers, will it be related to this?
@vicentt - thanks for you feedback regarding this issue - I will go through all app and test it.