[netcore] Ongoing work. (#13391)
[mono-project.git] / mono / tests / assembly-load-bytes-bindingredirect.cs
blobb9192e43017ece46231d79466d9e253414a98d61
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 int test_0_LoadBytesBindingRedirect ()
15 string path1 = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "assembly-load-dir1", "LibStrongName.dll");
17 // Try to load from dir1/LibStrongName.dll, but
18 // the assembly-load-bytes-bindingredirect.exe.config redirects all old versions to
19 // be mapped to version 2.0.0.0 which is in the assembly-load-dir2 directory
21 // In old versions of .net binding redirection did not apply to
22 // Load(byte[]), but since .NET 2 it does.
23 byte[] bytes1 = File.ReadAllBytes (path1);
24 Assembly asm1 = Assembly.Load (bytes1);
25 if (asm1 == null) {
26 Console.Error.WriteLine ("expected asm1 {0} to not be null", asm1);
27 return 1;
30 Type t1 = asm1.GetType ("LibClass");
31 if (t1 == null) {
32 Console.Error.WriteLine ("expected t1 {0} to not be null", t1);
33 return 2;
36 FieldInfo f1 = t1.GetField ("OnlyInVersion1");
37 if (f1 != null) {
38 Console.Error.WriteLine ("expected not to find field OnlyInVersion1, but got {0}", f1);
39 return 3;
42 FieldInfo f2 = t1.GetField ("OnlyInVersion2");
44 if (f2 == null) {
45 Console.Error.WriteLine ("expected field OnlyInVersion2 not to be null");
46 return 4;
49 if (f2.FieldType != typeof(int)) {
50 Console.Error.WriteLine ("Field OnlyInVersion2 has type {0}, expected int", f2.FieldType);
51 return 5;
53 return 0;