// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Reflection; using System.Diagnostics; namespace E { public class MainClass { public static void LoadEvent(object sender, AssemblyLoadEventArgs args) { Console.WriteLine("Load : " + ((AppDomain)sender).FriendlyName + " <- " + args.LoadedAssembly.FullName); } public static void Dump(AppDomain d) { Console.WriteLine(d.FriendlyName + " contains:"); foreach(Assembly a in d.GetAssemblies()) { Console.WriteLine("-" + a.FullName); } } public static void Test(string fnm) { AppDomain d = AppDomain.CreateDomain("MyDom"); //d.AssemblyLoad += new AssemblyLoadEventHandler(LoadEvent); // causes MyDom to load loader.exe - comment out to avoid object x = d.CreateInstanceAndUnwrap(fnm, "X"); Console.WriteLine(x); Console.WriteLine(x); Console.WriteLine(x); Dump(AppDomain.CurrentDomain); //Dump(d); // causes loader.exe to load x*.dll - comment out to avoid AppDomain.Unload(d); } public static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(LoadEvent); Test("x1"); Test("x2"); Test("x1"); Test("x2"); } } }