diff --git a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs
index b93889a94b5..aae3bd342ab 100644
--- a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs
+++ b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs
@@ -86,12 +86,12 @@ internal class NodeProviderOutOfProcTaskHost : NodeProviderOutOfProcBase, INodeP
///
/// A mapping of all of the INodePacketFactories wrapped by this provider.
///
- private IDictionary _nodeIdToPacketFactory;
+ private ConcurrentDictionary _nodeIdToPacketFactory;
///
/// A mapping of all of the INodePacketHandlers wrapped by this provider.
///
- private IDictionary _nodeIdToPacketHandler;
+ private ConcurrentDictionary _nodeIdToPacketHandler;
///
/// Keeps track of the set of nodes for which we have not yet received shutdown notification.
@@ -207,8 +207,8 @@ public void InitializeComponent(IBuildComponentHost host)
{
this.ComponentHost = host;
_nodeContexts = new ConcurrentDictionary();
- _nodeIdToPacketFactory = new Dictionary();
- _nodeIdToPacketHandler = new Dictionary();
+ _nodeIdToPacketFactory = new ConcurrentDictionary();
+ _nodeIdToPacketHandler = new ConcurrentDictionary();
_activeNodes = new HashSet();
_noNodesActiveEvent = new ManualResetEvent(true);
@@ -606,8 +606,8 @@ internal void DisconnectFromHost(int nodeId)
{
ErrorUtilities.VerifyThrow(_nodeIdToPacketFactory.ContainsKey(nodeId) && _nodeIdToPacketHandler.ContainsKey(nodeId), "Why are we trying to disconnect from a context that we already disconnected from? Did we call DisconnectFromHost twice?");
- _nodeIdToPacketFactory.Remove(nodeId);
- _nodeIdToPacketHandler.Remove(nodeId);
+ _nodeIdToPacketFactory.TryRemove(nodeId, out _);
+ _nodeIdToPacketHandler.TryRemove(nodeId, out _);
}
///