From b3f0ef0a009984922a010f8b90e7fc1880cfd282 Mon Sep 17 00:00:00 2001
From: Cyrille DUPUYDAUBY <dupdob@gmail.com>
Date: Fri, 8 Nov 2024 11:08:54 +0100
Subject: [PATCH] fix(embedded resources): Use concurrent dictionnary for
 resource cache (#3095)

fix: use concurrent dictionnary for resource cache
---
 .../Initialisation/EmbeddedResourcesGenerator.cs           | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs b/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs
index 895955d13..6085b719c 100644
--- a/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs
+++ b/src/Stryker.Core/Stryker.Core/Initialisation/EmbeddedResourcesGenerator.cs
@@ -2,6 +2,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Collections.Concurrent;
 using System.Diagnostics.CodeAnalysis;
 using System.IO;
 using System.Linq;
@@ -16,7 +17,7 @@ namespace Stryker.Core.Initialisation;
 [ExcludeFromCodeCoverage]
 public static class EmbeddedResourcesGenerator
 {
-    private static readonly Dictionary<string, IEnumerable<(ResourceDescription description, object context)>> _resourceDescriptions = new();
+    private static readonly ConcurrentDictionary<string, IEnumerable<(ResourceDescription description, object context)>> _resourceDescriptions = new();
 
     public static void ResetCache()
     {
@@ -30,7 +31,7 @@ public static IEnumerable<ResourceDescription> GetManifestResources(string assem
             using var module = LoadModule(assemblyPath);
             if (module is not null)
             {
-                _resourceDescriptions.Add(projectFilePath, ReadResourceDescriptionsFromModule(module).ToList());
+                _resourceDescriptions.TryAdd(projectFilePath, ReadResourceDescriptionsFromModule(module).ToList());
             }
 
             // Failed to load some or all resources from module, generate missing resources from disk
@@ -43,7 +44,7 @@ public static IEnumerable<ResourceDescription> GetManifestResources(string assem
             // Failed to load module, generate all resources from disk
             if (module is null)
             {
-                _resourceDescriptions.Add(projectFilePath, GenerateManifestResources(projectFilePath, rootNamespace, embeddedResources));
+                _resourceDescriptions.TryAdd(projectFilePath, GenerateManifestResources(projectFilePath, rootNamespace, embeddedResources));
             }
         }