[WinForms] Fix #18506 ActiveTracker, do not propagate message to control when it...
[mono-project.git] / mono / tests / assemblyresolve_event6.cs
blob9afb71c9589c24bb4f911c3c04d9c666e72cec76
1 using System;
2 using System.IO;
3 using System.Threading;
4 using System.Reflection;
6 public class App
8 public static int Main ()
10 /* Regression test for #58950: When the
11 * ReflectionOnlyAssemblyResolve event handler throws an
12 * exception, mono would unwind native code in the loader,
13 * which left stale coop handles on the coop handle stack.
14 * Then, the domain unload, asserted in
15 * mono_handle_stack_free_domain (). */
16 var d = AppDomain.CreateDomain ("TestDomain");
17 var o = d.CreateInstanceAndUnwrap (typeof (App).Assembly.FullName, "App/Work") as Work;
18 var r = o.DoSomething ();
19 if (r != 0)
20 return r;
21 AppDomain.Unload (d);
22 return 0;
25 public class MyExn : Exception {
26 public MyExn () : base ("MyReflectionResolveEventHandler threw") {}
29 public class Work : MarshalByRefObject {
30 public Work () { }
32 public int DoSomething ()
34 AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler (MyReflectionResolveEventHandler);
35 bool caught = false;
36 try {
37 Assembly a = Assembly.ReflectionOnlyLoadFrom ("assemblyresolve_asm.dll");
38 var t = a.GetType ("Asm2");
39 var m = t.GetMethod ("M"); // This triggers a load of TestBase
40 Console.Error.WriteLine ("got '{0}'", m);
41 } catch (FileNotFoundException e) {
42 Console.WriteLine ("caught FNFE {0}", e);
43 caught = true;
44 } catch (MyExn ) {
45 Console.Error.WriteLine ("caught MyExn, should've been a FNFE");
46 return 2;
48 if (!caught) {
49 Console.Error.WriteLine ("expected to catch a FNFE");
50 return 3;
52 return 0;
55 static Assembly MyReflectionResolveEventHandler (object sender, ResolveEventArgs args) {
56 Console.Error.WriteLine ($"Load event for: {args.Name}");
57 if (args.Name == "Test, Version=0.0.0.0, Culture=neutral" || args.Name == "Test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
58 return Assembly.ReflectionOnlyLoadFrom (Path.Combine (Directory.GetCurrentDirectory (), "assemblyresolve_deps", "Test.dll"));
59 // a request to load TestBase will throw here, which
60 // should be caught in the runtime
61 throw new MyExn ();