Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit aa30f97

Browse files
committed
[Ide] Fix crash in main toolbar after project is reloaded
If a multi-run configuration is selected in the main toolbar and a project is reloaded a crash can occur since the main toolbar has not updated its project mappings. Exception thrown: System.Collections.Generic.KeyNotFoundException: The given key 'MonoDevelop.CSharp.Project.CSharpProject' was not present in the dictionary. System.ThrowHelper.GetKeyNotFoundException(Object) System.ThrowHelper.ThrowKeyNotFoundException(Object) System.Collections.Generic.Dictionary`2[[MonoDevelop.Projects.SolutionItem],[MonoDevelop.Components.MainToolbar.ConfigurationMerger]].get_Item(SolutionItem) MonoDevelop.Components.MainToolbar.MainToolbarController.FillRuntimesForProject(List`1,SolutionItem,Int32&) MonoDevelop.Components.MainToolbar.MainToolbarController.FillRuntimes() MonoDevelop.Components.MainToolbar.MainToolbarController.NotifyConfigurationChange() MonoDevelop.Components.MainToolbar.MainToolbarController.HandleRuntimeChanged(Object,HandledEventArgs) The problem was that on reloading the main toolbar's configurationMerger dictionary was not updated. It still contained the old disposed project so the dictionary lookup would fail for the new reloaded project. To fix this when a project is reloaded the main toolbar's dictionary is now refreshed. Repro: 1. Create a solution with two projects. 2. Create a multiple startup run configuration with both projects. 3. Select the multi run configuration in the toolbar. 4. Edit one of the project files in the editor and save a change. 5. Change from Debug to Release in the main toolbar. Fixes VSTS #944654 - [FATAL] System.Collections.Generic.KeyNotFoundException exception in System.ThrowHelper.GetKeyNotFoundException()
1 parent 392e5dc commit aa30f97

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ void HandleCurrentSelectedSolutionChanged (object sender, SolutionEventArgs e)
575575
currentSolution.StartupConfigurationChanged -= HandleStartupItemChanged;
576576
currentSolution.Saved -= HandleSolutionSaved;
577577
currentSolution.EntrySaved -= HandleSolutionEntrySaved;
578+
currentSolution.SolutionItemAdded -= HandleSolutionItemAdded;
578579
}
579580

580581
currentSolution = e.Solution;
@@ -583,6 +584,7 @@ void HandleCurrentSelectedSolutionChanged (object sender, SolutionEventArgs e)
583584
currentSolution.StartupConfigurationChanged += HandleStartupItemChanged;
584585
currentSolution.Saved += HandleSolutionSaved;
585586
currentSolution.EntrySaved += HandleSolutionEntrySaved;
587+
currentSolution.SolutionItemAdded += HandleSolutionItemAdded;
586588
}
587589

588590
TrackStartupProject ();
@@ -625,6 +627,14 @@ void HandleSolutionEntrySaved (object sender, SolutionItemSavedEventArgs e)
625627
HandleSolutionSaved (sender, e);
626628
}
627629

630+
void HandleSolutionItemAdded (object sender, SolutionItemChangeEventArgs e)
631+
{
632+
// When a solution item is added due to a reload we need to ensure the configurationMergers dictionary is
633+
// using the new project and not the old disposed project.
634+
if (e.Reloading)
635+
UpdateCombos ();
636+
}
637+
628638
void HandleStartupItemChanged (object sender, EventArgs e)
629639
{
630640
TrackStartupProject ();

0 commit comments

Comments
 (0)