2 using System
.Threading
.Tasks
;
4 /* This is a regression test that checks that after an AssemblyLoad event fires
5 * in a domain, the domain can be unloaded. In bug # 56694, a
6 * System.Reflection.Assembly object from the unloaded domain was kept alive
7 * and crashed the GC. */
8 namespace AppDomainUnloadAsmLoad
12 static void Main(string[] args
)
14 // Need some threads in play
15 new Program().Run().Wait();
18 private async Task
Run()
20 var appDomain
= AppDomain
.CreateDomain("Test subdomain", null, AppDomain
.CurrentDomain
.SetupInformation
);
23 var driver
= (AppDomainTestDriver
)appDomain
.CreateInstanceAndUnwrap(typeof(AppDomainTestDriver
).Assembly
.FullName
,
24 typeof(AppDomainTestDriver
).FullName
);
29 AppDomain
.Unload(appDomain
);
34 class AppDomainTestDriver
: MarshalByRefObject
36 static AppDomainTestDriver()
38 // Needs a callback so that the runtime fires the
39 // AssembyLoad event for this domain and materializes a System.Reflection.Assembly
40 AppDomain
.CurrentDomain
.AssemblyLoad
+= CurrentDomain_AssemblyLoad
;
43 private static void CurrentDomain_AssemblyLoad(object sender
, AssemblyLoadEventArgs args
)
49 /* this can be any class from any assembly that hasn't
50 * already been loaded into the test domain.
51 * System.Xml.dll is good because all the tests link
52 * against it, but it's not otherwise used by this
54 var foo
= default(System
.Xml
.XmlException
);