AssemblyLoadContext.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. namespace System.Runtime.Loader
  5. {
  6. public abstract class AssemblyLoadContext
  7. {
  8. protected abstract Assembly Load(AssemblyName assemblyName);
  9. protected Assembly LoadFromAssemblyPath(string assemblyPath)
  10. {
  11. if (assemblyPath == null)
  12. throw new ArgumentNullException("assemblyPath");
  13. if (!Path.IsPathRooted(assemblyPath))
  14. throw new ArgumentException("Gimme an absolute path " + assemblyPath + " XXX " + Path.GetPathRoot(assemblyPath), "assemblyPath");
  15. return Assembly.LoadFrom (assemblyPath);
  16. }
  17. public Assembly LoadFromAssemblyName(AssemblyName assemblyName)
  18. {
  19. // AssemblyName is mutable. Cache the expected name before anybody gets a chance to modify it.
  20. string requestedSimpleName = assemblyName.Name;
  21. Assembly assembly = Load(assemblyName);
  22. if (assembly == null)
  23. throw new FileLoadException("File not found", requestedSimpleName);
  24. return assembly;
  25. }
  26. public static AssemblyName GetAssemblyName(string assemblyPath)
  27. {
  28. if (!File.Exists (assemblyPath))
  29. throw new Exception ("file not found");
  30. return new AssemblyName (Path.GetFileName (assemblyPath));
  31. }
  32. }
  33. }