This repository has been archived by the owner on Oct 6, 2019. It is now read-only.
DNN-30135 - Issue when loading the Persona Bar: Not Thread Safe #1126
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.
Fixes #1125
Summary
The problem lies in "Dnn.PersonaBar.Library.Repository.PersonaBarRepository.GetMenuItem(string identifier)" method which is called from "Evoq.PersonaBar.UI.Controllers.EvoqPersonaBarContainer.Initialize(UserControl personaBarControl)". GetMenuItem method doesn't exist in the StackTrace because JIT (Just-In-Time) Compiler does Inline Code Optimizations for release builds which basically means that some methods (especially like the ones that are only a few lines) get inlined into the previous method chain for performance reasons. Therefore, if you have a method call chain like A -> B -> C, it might become A -> B if C is inlined (you might think of it as method C's code gets copied under method B).
Using a list instance which might change state in loops (FirstOrDefault method iterates the elements one by one which behaves like a loop) will raise that error when the list gets updated while iterating. The solution is to use ToList method to copy the list's current state into another list and then use it instead for iteration. You can watch the following video I shot which demonstrates the issue: https://drive.google.com/open?id=13bneeDRu2aqicSvJ-QtV2okoPUivkHh4