2022-01-22 20:06:58 +08:00
|
|
|
|
#if SERVER
|
|
|
|
|
using System.IO;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
using System.Reflection;
|
2022-01-22 20:06:58 +08:00
|
|
|
|
using System.Runtime.Loader;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public static class DllHelper
|
|
|
|
|
{
|
2022-01-22 20:06:58 +08:00
|
|
|
|
private static AssemblyLoadContext assemblyLoadContext;
|
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static Assembly GetHotfixAssembly()
|
|
|
|
|
{
|
2022-01-22 20:06:58 +08:00
|
|
|
|
assemblyLoadContext?.Unload();
|
|
|
|
|
System.GC.Collect();
|
|
|
|
|
assemblyLoadContext = new AssemblyLoadContext("Hotfix", true);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
byte[] dllBytes = File.ReadAllBytes("./Hotfix.dll");
|
|
|
|
|
byte[] pdbBytes = File.ReadAllBytes("./Hotfix.pdb");
|
2022-01-22 20:06:58 +08:00
|
|
|
|
Assembly assembly = assemblyLoadContext.LoadFromStream(new MemoryStream(dllBytes), new MemoryStream(pdbBytes));
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return assembly;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-22 20:06:58 +08:00
|
|
|
|
#endif
|