Skip to content

Commit

Permalink
Fix "collection modified" exception
Browse files Browse the repository at this point in the history
When signalling project close to an info bar entry, if there are no other remaining projects associated with that info bar, it will be removed from the collection. That triggers an exception.

The fix is to make a defensive copy before enumerating, so that the original can be safely modified while the copy is enumerated.
  • Loading branch information
drewnoakes committed Dec 12, 2024
1 parent 24eabd0 commit 2876142
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public VsInfoBarService(
{
lock (s_entries)
{
foreach (InfoBar entry in s_entries)
// Copy the list to avoid "collection modified during enumeration" exceptions,
// as when the last project associated with an info bar is closed, we will
// remove that entry from the list.
foreach (InfoBar entry in s_entries.ToList())
{
entry.OnProjectClosed(_project);
}
Expand Down

0 comments on commit 2876142

Please sign in to comment.