From 276cd0a4a8049a2490cae443e43807b0401b78a1 Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 22 Jan 2024 21:59:47 +0800 Subject: [PATCH] =?UTF-8?q?[change]=20AssemblyCacheBase=E6=96=B0=E5=A2=9ET?= =?UTF-8?q?ryLoadModule=E6=8E=A5=E5=8F=A3=20[change]=20AssemblyCacheBase?= =?UTF-8?q?=E5=8A=A0=E8=BD=BDModule=E6=97=B6=E5=85=88File.ReadAllBytes?= =?UTF-8?q?=E8=AF=BB=E5=8F=96dll=E5=86=85=E5=AE=B9=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8DDispose=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Meta/AssemblyCacheBase.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Editor/Meta/AssemblyCacheBase.cs b/Editor/Meta/AssemblyCacheBase.cs index 82fb007..1816f12 100644 --- a/Editor/Meta/AssemblyCacheBase.cs +++ b/Editor/Meta/AssemblyCacheBase.cs @@ -1,6 +1,7 @@ using dnlib.DotNet; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,6 +16,9 @@ namespace HybridCLR.Editor.Meta private bool disposedValue; private bool _loadedNetstandard; + + public ModuleContext ModCtx => _modCtx; + public Dictionary LoadedModules { get; } = new Dictionary(); private readonly List _loadedModulesIncludeNetstandard = new List(); @@ -28,6 +32,17 @@ namespace HybridCLR.Editor.Meta _asmResolver.UseGAC = false; } + + public ModuleDefMD TryLoadModule(string moduleName, bool loadReferenceAssemblies = true) + { + string dllPath = _assemblyPathResolver.ResolveAssembly(moduleName, false); + if (string.IsNullOrEmpty(dllPath)) + { + return null; + } + return LoadModule(moduleName, loadReferenceAssemblies); + } + public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true) { // Debug.Log($"load module:{moduleName}"); @@ -75,7 +90,7 @@ namespace HybridCLR.Editor.Meta private ModuleDefMD DoLoadModule(string dllPath) { //Debug.Log($"do load module:{dllPath}"); - ModuleDefMD mod = ModuleDefMD.Load(dllPath, _modCtx); + ModuleDefMD mod = ModuleDefMD.Load(File.ReadAllBytes(dllPath), _modCtx); _asmResolver.AddToCache(mod); _loadedModulesIncludeNetstandard.Add(mod); return mod;