Merge pull request #4938 from kumpera/optimize_ref_queries
[mono.git] / mono / tests / appdomain-unload-asmload.cs
1 using System;
2 using System.Threading.Tasks;
3
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
9 {
10         class Program
11         {
12                 static void Main(string[] args)
13                 {
14                         // Need some threads in play
15                         new Program().Run().Wait();
16                 }
17
18                 private async Task Run()
19                 {
20                         var appDomain = AppDomain.CreateDomain("Test subdomain", null, AppDomain.CurrentDomain.SetupInformation);
21                         try
22                         {
23                                 var driver = (AppDomainTestDriver)appDomain.CreateInstanceAndUnwrap(typeof(AppDomainTestDriver).Assembly.FullName,
24                                                                                                     typeof(AppDomainTestDriver).FullName);
25                                 driver.Test();
26                         }
27                         finally
28                         {
29                                 AppDomain.Unload(appDomain);
30                         }
31                 }
32         }
33
34         class AppDomainTestDriver : MarshalByRefObject
35         {
36                 static AppDomainTestDriver()
37                 {
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;
41                 }
42
43                 private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
44                 {
45                 }
46
47                 internal void Test()
48                 {
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
53                          * domain. */
54                         var foo = default(System.Xml.XmlException);
55                 }
56     }
57 }