DllHelper.cs 715 B

12345678910111213141516171819202122
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Runtime.Loader;
  4. namespace ET
  5. {
  6. public static class DllHelper
  7. {
  8. private static AssemblyLoadContext assemblyLoadContext;
  9. public static Assembly GetHotfixAssembly()
  10. {
  11. assemblyLoadContext?.Unload();
  12. System.GC.Collect();
  13. assemblyLoadContext = new AssemblyLoadContext("Hotfix", true);
  14. byte[] dllBytes = File.ReadAllBytes("./Hotfix.dll");
  15. byte[] pdbBytes = File.ReadAllBytes("./Hotfix.pdb");
  16. Assembly assembly = assemblyLoadContext.LoadFromStream(new MemoryStream(dllBytes), new MemoryStream(pdbBytes));
  17. return assembly;
  18. }
  19. }
  20. }