Revert "[2018-06] [System]: `MonoTlsStream` is now `IDisposable` and cleans up on...
[mono-project.git] / mono / tests / appdomain-unload-asmload.cs
blob5f79890ca53a7dac42d30ee78327291737432a27
1 using System;
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
10 class Program
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);
21 try
23 var driver = (AppDomainTestDriver)appDomain.CreateInstanceAndUnwrap(typeof(AppDomainTestDriver).Assembly.FullName,
24 typeof(AppDomainTestDriver).FullName);
25 driver.Test();
27 finally
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)
47 internal void Test()
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);