Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception 'An element with the same key but a different value already exists. Key: OrchardCore.Roles.Models.RolesDocument' on startup #4805

Closed
netwavebe opened this issue Nov 14, 2019 · 9 comments · Fixed by #4810
Labels
Milestone

Comments

@netwavebe
Copy link
Contributor

I updated my solution to dev 3 days ago. Since that version, this exception is logged serveral times a day:

2019-11-13 22:05:16.3429|Default|8000024f-0008-7300-b63f-84710c7967bb||Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|ERROR|An unhandled exception has occurred while executing the request. System.ArgumentException: An element with the same key but a different value already exists. Key: OrchardCore.Roles.Models.RolesDocument
   at System.Collections.Immutable.ImmutableDictionary`2.HashBucket.Add(TKey key, TValue value, IEqualityComparer`1 keyOnlyComparer, IEqualityComparer`1 valueComparer, KeyCollisionBehavior behavior, OperationResult& result)
   at System.Collections.Immutable.ImmutableDictionary`2.Add(TKey key, TValue value, KeyCollisionBehavior behavior, MutationInput origin)
   at System.Collections.Immutable.ImmutableDictionary`2.Add(TKey key, TValue value)
   at YesSql.Store.GetIdAccessor(Type tContainer, String name)
   at YesSql.Session.Get[T](IList`1 documents)
   at YesSql.Services.DefaultQuery.Query`1.FirstOrDefaultImpl()
   at OrchardCore.Data.SessionHelper.LoadForUpdateAsync[T](Func`1 factory) in D:\GitHub\www.t-shirtskempen.be\src\OrchardCore\OrchardCore.Data\SessionHelper.cs:line 30
   at OrchardCore.Roles.Services.RoleStore.FindByNameAsync(String normalizedRoleName, CancellationToken cancellationToken) in D:\GitHub\www.t-shirtskempen.be\src\OrchardCore.Modules\OrchardCore.Roles\Services\RoleStore.cs:line 149
   at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory`2.GenerateClaimsAsync(TUser user)
   at OrchardCore.Users.Services.DefaultUserClaimsPrincipalFactory.GenerateClaimsAsync(IUser user) in D:\GitHub\www.t-shirtskempen.be\src\OrchardCore\OrchardCore.Users.Core\Services\DefaultUserClaimsPrincipalFactory.cs:line 28
   at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory`1.CreateAsync(TUser user)
   at Microsoft.AspNetCore.Identity.SignInManager`1.CreateUserPrincipalAsync(TUser user)
   at Microsoft.AspNetCore.Identity.SecurityStampValidator`1.SecurityStampVerified(TUser user, CookieValidatePrincipalContext context)
   at Microsoft.AspNetCore.Identity.SecurityStampValidator`1.ValidateAsync(CookieValidatePrincipalContext context)
   at Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
   at OrchardCore.Diagnostics.DiagnosticsStartupFilter.<>c__DisplayClass3_0.<<Configure>b__1>d.MoveNext() in D:\GitHub\www.t-shirtskempen.be\src\OrchardCore.Modules\OrchardCore.Diagnostics\DiagnosticsStartupFilter.cs:line 36

When I did encouter this issue myself yesterday, I was not doing anything. It happened when I first browsed to the website. I got a 500. After F5 the site worked fine. So I assume it's some kind of startup issue.

@jtkech : it might be related to #4001

@netwavebe
Copy link
Contributor Author

Complete callstack:
4805.txt

@sebastienros sebastienros added this to the 1.0 milestone Nov 14, 2019
@jtkech
Copy link
Member

jtkech commented Nov 14, 2019

Big power outage so from my phone as i could get a poor conection
Just to say that i found why, i will comment it asap

@jtkech
Copy link
Member

jtkech commented Nov 14, 2019

In yessql Store, on an immutable dico we use TryGetValue then do something then Add that may fail if the entry has just been set by another thread, we would need to use SetItem in place that doesn’t fail in this case.

It was working before because we were using the cached value, here we would need to do the same to prevent one db query, but when updating user roles we use the aspnet user manager that also call in this case FindByNameAsync. That’s why in this method we load data from the database.

For this last thing i will see what we can do as soon as i can start my computer, i still don’t have any electrical power.

Meanwhile i think that this issue can be easily fixed through yessql.

@Skrypt
Copy link
Contributor

Skrypt commented Nov 15, 2019

Sorry to have infected your country with our power outage @jtkech

@sebastienros
Copy link
Member

@jtkech which collection is it ?

@sebastienros
Copy link
Member

I see ...

@jtkech
Copy link
Member

jtkech commented Nov 15, 2019

@Skrypt no problem, still not any power, i can just get Time to Time some connection from my phone, i’am under the snow, becomes to be very cold at home, it looks like your recent storry, we now are 2 black cats ;)

@sebastienros in Store.cs, maybe same problem with different dicos

sebastienros added a commit that referenced this issue Nov 15, 2019
@sebastienros
Copy link
Member

Just submitted a PR that should fix it. It was worse than what is described here

sebastienros added a commit that referenced this issue Nov 15, 2019
@jtkech
Copy link
Member

jtkech commented Nov 15, 2019

yes, just saw your pr, not so worse ;)

@sebastienros sebastienros modified the milestones: 1.0, rc2 Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants