[2020-02] Avoid following invalid pointers in mono_w32process_get_modules on Darwin...
[mono-project.git] / mono / tests / appdomain-marshalbyref-assemblyload.cs
blobb8c01d7bad10840808addf66f0e9cbbd02553532
1 using System;
2 using System.IO;
3 using System.Security.Policy;
5 public class Test {
6 public static int Main ()
8 var dir1 = Path.GetDirectoryName (typeof (Test).Assembly.Location);
9 var dir2 = "appdomain-marshalbyref-assemblyload2";
10 var domain = CreateDomain (dir2);
11 var path1 = Path.Combine (dir1, "MidAssembly.dll");
12 object o = domain.CreateInstanceFromAndUnwrap (path1, "MidAssembly.MidClass");
13 var mc = o as MidAssembly.MidClass;
14 var l = new LeafAssembly.Leaf ();
15 /* passing Leaf to MidMethod should /not/ cause
16 * place2/LeafAssembly.dll to be loaded in the new remote
17 * domain */
18 mc.MidMethod (l);
19 /* this line will pre-load place1/LeafAssembly.dll into the
20 * remote domain.
22 mc.ForceLoadFrom (Path.Combine (dir1, "LeafAssembly.dll"));
23 /* This method calls a class from LeafAssembly (which is only
24 * defined in the place1 version of the class), so if the
25 * place2 version had been loaded instead, it will trigger a
26 * MissingMethodException */
27 mc.DoSomeAction ();
28 return 0;
31 public static AppDomain CreateDomain (string newpath)
33 var appDomainSetup = new AppDomainSetup ();
34 appDomainSetup.ApplicationBase = newpath;
35 var appDomain = AppDomain.CreateDomain ("MyDomainName", new Evidence (), appDomainSetup);
36 return appDomain;