[tests] Add coreclr GC stress tests
[mono-project.git] / acceptance-tests / GCStressTests / AssemblyLoadContext.cs
blobb3a2c48345360db2036caee4eab4290a45454f16
1 using System;
2 using System.IO;
3 using System.Reflection;
5 namespace System.Runtime.Loader
7 public abstract class AssemblyLoadContext
9 protected abstract Assembly Load(AssemblyName assemblyName);
11 protected Assembly LoadFromAssemblyPath(string assemblyPath)
13 if (assemblyPath == null)
14 throw new ArgumentNullException("assemblyPath");
16 if (!Path.IsPathRooted(assemblyPath))
17 throw new ArgumentException("Gimme an absolute path " + assemblyPath + " XXX " + Path.GetPathRoot(assemblyPath), "assemblyPath");
19 return Assembly.LoadFrom (assemblyPath);
22 public Assembly LoadFromAssemblyName(AssemblyName assemblyName)
24 // AssemblyName is mutable. Cache the expected name before anybody gets a chance to modify it.
25 string requestedSimpleName = assemblyName.Name;
27 Assembly assembly = Load(assemblyName);
28 if (assembly == null)
29 throw new FileLoadException("File not found", requestedSimpleName);
31 return assembly;
34 public static AssemblyName GetAssemblyName(string assemblyPath)
36 if (!File.Exists (assemblyPath))
37 throw new Exception ("file not found");
38 return new AssemblyName (Path.GetFileName (assemblyPath));