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

Commit b00b847

Browse files
Rodrigo Moyarodrmoya
authored andcommitted
[AspNetCore] Avoid exception when saving run configurations
When loading a ASP.NET Core project, OnCreateRunConfiguration is called for the "Default" config, and the ASP.NET Core implementation does the syncing of the launchSettings.json file, in which case it enumerates the existing RunConfigurations in the Project, which in turn calls again OnCreateRunConfiguration to create the "Default" again. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1005086
1 parent e0ac3c6 commit b00b847

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreProjectExtension.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ protected override ProjectRunConfiguration OnCreateRunConfiguration (string name
6464
profile = launchProfileProvider.Profiles [key];
6565
}
6666

67-
var aspnetconf = new AspNetCoreRunConfiguration (name, profile);
68-
aspnetconf.LaunchProfileProvider = launchProfileProvider;
67+
var aspnetconf = new AspNetCoreRunConfiguration (name, profile) {
68+
LaunchProfileProvider = launchProfileProvider
69+
};
70+
if (aspNetCoreRunConfs.TryGetValue (name, out var existingConf)) {
71+
// This can be called a few times with the same config at load time,
72+
// so make sure we clean up the previous version
73+
existingConf.SaveRequested -= Aspnetconf_Save;
74+
}
6975
aspnetconf.SaveRequested += Aspnetconf_Save;
70-
aspNetCoreRunConfs.Add (name, aspnetconf);
76+
aspNetCoreRunConfs [name] = aspnetconf;
7177
return aspnetconf;
7278
}
7379

0 commit comments

Comments
 (0)