Repository navigation
Avoid exception: An item with the same key has already been added. Key: MicrosoftIdentityError - #1382
Merged
Merged
Conversation
β¦y: MicrosoftIdentityError This exception occurs sometimes when there are errors during login. It's not always the case but perhaps something to do with Temp Data not being cleared during debugging/testing and restarting. In any case, it's easily solved by just setting the temp data value instead of adding it. Stack trace ``` ArgumentException: An item with the same key has already been added. Key: MicrosoftIdentityError System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior) System.Collections.Generic.Dictionary<TKey, TValue>.Add(TKey key, TValue value) Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary.Add(string key, object value) Microsoft.Identity.Web.TempDataLoginErrorAccessor.SetMessage(HttpContext context, string message) Microsoft.Identity.Web.AzureADB2COpenIDConnectEventHandlers.OnRemoteFailure(RemoteFailureContext context) Microsoft.Identity.Web.MicrosoftIdentityWebAppAuthenticationBuilderExtensions+<>c__DisplayClass5_2+<<AddMicrosoftIdentityWebAppInternal>b__5>d.MoveNext() ```
jennyf19
approved these changes
Aug 12, 2021
jennyf19
left a comment
Collaborator
There was a problem hiding this comment.
great. thanks Shannon Deminick (@Shazwazza)
Collaborator
|
Included in 1.16 release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This exception occurs sometimes when there are errors during login. It's not always the case but perhaps something to do with Temp Data not being cleared during debugging/testing and restarting. In any case, it's easily solved by just setting the temp data value instead of adding it.
Update: I've replaced the
ILoginErrorAccessorwith my own just see how this is caused and it's not due to Temp Data not being cleared. It ends up being called twice if you accidentally redirect to the same oicd handler address that is handling it - then the same key is added twice. Obviously not common and shouldn't actually occur (oops!) but still can be avoided by not using "Set"Stack trace