From c91708fd9bbbfe1b26b9b088a257cddab98e6eed Mon Sep 17 00:00:00 2001 From: Rudolf Kolbe Date: Mon, 2 Jun 2025 17:59:40 +0200 Subject: [PATCH 1/2] MonoCecilTempGenerator - only check path if not already loaded --- .../MonoCecilTempGenerator.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs index dd6d562..7e6643c 100644 --- a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs +++ b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs @@ -40,13 +40,24 @@ public AssetTypeTemplateField GetTemplateField(AssetTypeTemplateField baseField, assemblyName += ".dll"; } - string assemblyPath = Path.Combine(managedPath, assemblyName); - if (!File.Exists(assemblyPath)) + List newFields; + + // if the assembly is already loaded, use it + if (loadedAssemblies.ContainsKey(assemblyName)) { - return null; + AssemblyDefinition asmDef = loadedAssemblies[assemblyName]; + newFields = Read(asmDef, nameSpace, className, unityVersion); + } + else + // otherwise, try to read it from the managed path + { + string assemblyPath = Path.Combine(managedPath, assemblyName); + if (!File.Exists(assemblyPath)) + { + return null; + } + newFields = Read(assemblyPath, nameSpace, className, unityVersion); } - - List newFields = Read(assemblyPath, nameSpace, className, unityVersion); AssetTypeTemplateField newBaseField = baseField.Clone(); newBaseField.Children.AddRange(newFields); From 85a3d02755a52a52ef52c5a9a7360304c1582aa4 Mon Sep 17 00:00:00 2001 From: Rudolf Kolbe Date: Mon, 2 Jun 2025 20:04:47 +0200 Subject: [PATCH 2/2] MonoCecilTempGenerator - use lock for accessing loadedAssemblies in GetTemplateField --- AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs index 7e6643c..b033fbb 100644 --- a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs +++ b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs @@ -40,16 +40,19 @@ public AssetTypeTemplateField GetTemplateField(AssetTypeTemplateField baseField, assemblyName += ".dll"; } - List newFields; + List newFields = null; // if the assembly is already loaded, use it - if (loadedAssemblies.ContainsKey(assemblyName)) + lock (loadedAssemblies) { - AssemblyDefinition asmDef = loadedAssemblies[assemblyName]; - newFields = Read(asmDef, nameSpace, className, unityVersion); + if (loadedAssemblies.TryGetValue(assemblyName, out AssemblyDefinition asmDef)) + { + newFields = Read(asmDef, nameSpace, className, unityVersion); + } } - else + // otherwise, try to read it from the managed path + if (newFields == null) { string assemblyPath = Path.Combine(managedPath, assemblyName); if (!File.Exists(assemblyPath))