3 using System.Threading;
4 using System.Reflection;
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 ();
25 public class MyExn : Exception {
26 public MyExn () : base ("MyReflectionResolveEventHandler threw") {}
29 public class Work : MarshalByRefObject {
32 public int DoSomething ()
34 AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler (MyReflectionResolveEventHandler);
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);
45 Console.Error.WriteLine ("caught MyExn, should've been a FNFE");
49 Console.Error.WriteLine ("expected to catch a FNFE");
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