Fix lookup for all SourceLink mappings, prefer local file over SourceLink
[mono-project.git] / mono / tests / assembly-loadfrom-simplename.cs
blob43bce8b301cd6327d286172ab3bf4d725d2d4308
1 using System;
2 using System.IO;
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) {
13 bool result = false;
14 foreach (var asm in AppDomain.CurrentDomain.GetAssemblies ()) {
15 var p = asm.Location;
16 if (p != null && p.Contains (partialPath)) {
17 Console.Error.WriteLine ("Assembly {0} was unexpectedly loaded from '{1}'", asm.FullName, p);
18 result = true;
21 return result;
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);
34 if (asm1 == null) {
35 Console.Error.WriteLine ("expected asm1 {0} to not be null", asm1);
36 return 1;
39 Assembly asm2 = Assembly.LoadFrom (path2);
40 if (asm2 == null) {
41 Console.Error.WriteLine ("expected asm2 {1} to not be null", asm2);
42 return 2;
45 Type t1 = asm1.GetType ("MidClass");
46 if (t1 == null) {
47 Console.Error.WriteLine ("expected t1 {0} to not be null", t1);
48 return 3;
51 // causes the reference to libsimplename to be resolved
52 var o = Activator.CreateInstance (t1);
54 FieldInfo f1 = t1.GetField ("X");
55 if (f1 == null) {
56 Console.Error.WriteLine ("expected to get field MidClass.X, but got {0}", f1);
57 return 4;
60 int n = (int)f1.GetValue (o);
61 if (n != 2) {
62 Console.Error.WriteLine ("expected to get the value 2 from MidClass.X, but got {0}", n);
63 return 5;
66 if (AnyLoadedAssemblyFrom ("assembly-load-dir1")) {
67 Console.Error.WriteLine ("An unexpected load event happened (see above)");
68 return 6;
71 return 0;