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

Commit 021be87

Browse files
mrwardmonojenkins
authored andcommitted
[Core] Make MSBuildPropertyGroupEvaluated thread safe
Adding a new .json file to a ASP.NET Core 3.1 project resulted in the files not being displayed in the Properties folder due to the project configuration's Properties being updated on a background thread on saving and the UI thread reading these properties to determine if a file is visible in the Solution pad. Switch to using a concurrent dictionary in MSBuildPropertyGroupEvaluated. System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[TKey,TValue].MoveNext () [0x00085] in mono-x64/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:1628 at MonoDevelop.Projects.MSBuild.MSBuildEvaluatedPropertyCollection+<MonoDevelop-Projects-IPropertySet-GetProperties>d__11.MoveNext () [0x0008e] in monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupEvaluated.cs:207 at MonoDevelop.Projects.Project+<GetVisibleFiles>d__143.MoveNext () [0x0017d] in monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:1231 at MonoDevelop.Ide.Gui.Pads.ProjectPad.FolderNodeBuilder.GetFolderContent (MonoDevelop.Projects.Project project, System.String folder, System.Collections.Generic.List`1[MonoDevelop.Projects.ProjectFile]& files, System.Collections.Generic.List`1[System.String]& folders) [0x00149] in monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/FolderNodeBuilder.cs:87 at MonoDevelop.Ide.Gui.Pads.ProjectPad.FolderNodeBuilder.BuildChildNodes (MonoDevelop.Ide.Gui.Components.ITreeBuilder builder, System.Object dataObject) [0x00048] in monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/FolderNodeBuilder.cs:74 at MonoDevelop.Ide.Gui.Components.ExtensibleTreeView+TransactedTreeBuilder.FillNode () [0x00082] in monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/TransactedTreeBuilder.cs:522
1 parent e08e58f commit 021be87

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupEvaluated.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
// THE SOFTWARE.
2626
using System;
27+
using System.Collections.Concurrent;
2728
using System.Collections.Generic;
2829
using System.Xml.Linq;
2930
using MonoDevelop.Core;
@@ -32,7 +33,7 @@ namespace MonoDevelop.Projects.MSBuild
3233
{
3334
class MSBuildPropertyGroupEvaluated: MSBuildNode, IMSBuildPropertyGroupEvaluated, IMSBuildProjectObject
3435
{
35-
protected Dictionary<string,IMSBuildPropertyEvaluated> properties = new Dictionary<string, IMSBuildPropertyEvaluated> (StringComparer.OrdinalIgnoreCase);
36+
protected ConcurrentDictionary<string, IMSBuildPropertyEvaluated> properties = new ConcurrentDictionary<string, IMSBuildPropertyEvaluated> (StringComparer.OrdinalIgnoreCase);
3637
MSBuildEngine engine;
3738

3839
internal MSBuildPropertyGroupEvaluated (MSBuildProject parent)
@@ -70,7 +71,7 @@ internal void SetProperty (string key, IMSBuildPropertyEvaluated value)
7071

7172
internal void SetProperties (Dictionary<string,IMSBuildPropertyEvaluated> properties)
7273
{
73-
this.properties = properties;
74+
this.properties = new ConcurrentDictionary<string, IMSBuildPropertyEvaluated> (properties, StringComparer.OrdinalIgnoreCase);
7475
}
7576

7677
public IEnumerable<IMSBuildPropertyEvaluated> GetProperties ()
@@ -80,7 +81,7 @@ public IEnumerable<IMSBuildPropertyEvaluated> GetProperties ()
8081

8182
internal bool RemoveProperty (string name)
8283
{
83-
return properties.Remove (name);
84+
return properties.TryRemove (name, out _);
8485
}
8586

8687
public string GetValue (string name, string defaultValue = null)
@@ -280,7 +281,7 @@ void IPropertyGroupListener.PropertyRemoved (MSBuildProperty prop)
280281
// that property group property.
281282
if (ep.IsNew || !prop.IsNew) {
282283
ep.IsNew = false;
283-
properties.Remove (ep.Name);
284+
properties.TryRemove (ep.Name, out _);
284285
}
285286
}
286287
}

0 commit comments

Comments
 (0)