3 using System
.Reflection
;
5 public class TestAssemblyLoad
{
7 public static int Main ()
9 return TestDriver
.RunTests (typeof (TestAssemblyLoad
));
12 public static bool AnyLoadedAssemblyFrom (string partialPath
) {
14 foreach (var asm
in AppDomain
.CurrentDomain
.GetAssemblies ()) {
16 if (p
!= null && p
.Contains (partialPath
)) {
17 Console
.Error
.WriteLine ("Assembly {0} was unexpectedly loaded from '{1}'", asm
.FullName
, p
);
24 public static int test_0_LoadFromSimpleNamePreload ()
27 // The Makefile arranges for assembly-dep-simplename.dll to reference "LibSimpleName, Version=1.0.0.0"
28 // At runtime, we will preload "libsimplename, Version=2.0.0.0" (note case and version are different).
29 // When we create an instance from assembly-dep-simplename, we expect it to bind to the preloaded libsimplename Version=2.0.0.0, and for no additional assemblies to be loaded.
30 string path1
= Path
.Combine (AppDomain
.CurrentDomain
.BaseDirectory
, "assembly-dep-simplename.dll");
31 string path2
= Path
.Combine (AppDomain
.CurrentDomain
.BaseDirectory
, "assembly-load-dir2", "libsimplename.dll");
33 Assembly asm1
= Assembly
.LoadFrom (path1
);
35 Console
.Error
.WriteLine ("expected asm1 {0} to not be null", asm1
);
39 Assembly asm2
= Assembly
.LoadFrom (path2
);
41 Console
.Error
.WriteLine ("expected asm2 {1} to not be null", asm2
);
45 Type t1
= asm1
.GetType ("MidClass");
47 Console
.Error
.WriteLine ("expected t1 {0} to not be null", t1
);
51 // causes the reference to libsimplename to be resolved
52 var o
= Activator
.CreateInstance (t1
);
54 FieldInfo f1
= t1
.GetField ("X");
56 Console
.Error
.WriteLine ("expected to get field MidClass.X, but got {0}", f1
);
60 int n
= (int)f1
.GetValue (o
);
62 Console
.Error
.WriteLine ("expected to get the value 2 from MidClass.X, but got {0}", n
);
66 if (AnyLoadedAssemblyFrom ("assembly-load-dir1")) {
67 Console
.Error
.WriteLine ("An unexpected load event happened (see above)");