Bootstrap.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Reflection;
  3. using System.Runtime.InteropServices;
  4. using System.Runtime.Loader;
  5. // This must be in TPA list
  6. public class AtomicLoadContext : AssemblyLoadContext
  7. {
  8. public static void Startup()
  9. {
  10. AssemblyLoadContext.InitializeDefaultContext(new AtomicLoadContext());
  11. Console.WriteLine("Bootstrap Startup");
  12. }
  13. [DllImport("dl")]
  14. protected static extern IntPtr dlopen(string filename, int flags);
  15. protected override IntPtr LoadUnmanagedDll(String unmanagedDllName)
  16. {
  17. if (unmanagedDllName == "__Internal")
  18. {
  19. return dlopen(null, 1 /*RTLD_LAZY*/);
  20. }
  21. // do we need to walk paths here?
  22. return dlopen(unmanagedDllName, 1 /*RTLD_LAZY*/);
  23. }
  24. protected override Assembly Load(AssemblyName assemblyName)
  25. {
  26. Console.WriteLine(assemblyName.Name);
  27. Assembly assembly = null;
  28. try {
  29. assembly = LoadFromAssemblyPath("/Users/josh/Desktop/" + assemblyName.Name + ".dll");
  30. } catch (Exception e)
  31. {
  32. Console.WriteLine(e.Message);
  33. }
  34. Console.WriteLine("Assembly: " + assembly);
  35. return assembly;
  36. }
  37. }