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