diff --git a/MelonLoader/CompatibilityLayers/MelonCompatibilityLayer.cs b/MelonLoader/CompatibilityLayers/MelonCompatibilityLayer.cs index 7113e457..464b6bdb 100644 --- a/MelonLoader/CompatibilityLayers/MelonCompatibilityLayer.cs +++ b/MelonLoader/CompatibilityLayers/MelonCompatibilityLayer.cs @@ -64,7 +64,7 @@ internal static void LoadModules() continue; MelonDebug.Msg($"Loading MelonModule '{m.fullPath}'"); - MelonModule.Load(m); + m.moduleGC = MelonModule.Load(m); } foreach (var file in Directory.GetFiles(baseDirectory)) diff --git a/MelonLoader/Modules/MelonModule.cs b/MelonLoader/Modules/MelonModule.cs index 46a46afb..ee23a5f8 100644 --- a/MelonLoader/Modules/MelonModule.cs +++ b/MelonLoader/Modules/MelonModule.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Reflection; +#if NET6_0_OR_GREATER +using System.Runtime.Loader; +#endif + namespace MelonLoader.Modules { /// @@ -53,7 +57,11 @@ internal static MelonModule Load(Info moduleInfo) Assembly asm; try { +#if NET6_0_OR_GREATER + asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(moduleInfo.fullPath); +#else asm = Assembly.LoadFrom(moduleInfo.fullPath); +#endif } catch (Exception ex) { @@ -115,6 +123,7 @@ public class Info public readonly string fullPath; internal readonly Func shouldBeRemoved; internal readonly Func shouldBeIgnored; + internal MelonModule moduleGC; internal Info(string path, Func shouldBeIgnored = null, Func shouldBeRemoved = null) {