2 // reference-loader.cs:
4 // Test for reference assembly loading
8 using System.Reflection;
11 public static int Main (string[] args)
13 return TestDriver.RunTests (typeof (Tests), args);
16 public static int test_0_loadFrom_reference ()
18 // Check that loading a reference assembly by filename for execution is an error
20 var a = Assembly.LoadFrom ("./TestingReferenceAssembly.dll");
21 } catch (BadImageFormatException exn) {
22 // .NET Framework 4.6.2 throws BIFE here.
28 public static int test_0_load_reference ()
30 // Check that loading a reference assembly for execution is an error
32 var an = new AssemblyName ("TestingReferenceAssembly");
33 var a = Assembly.Load (an);
34 } catch (FileNotFoundException exn) {
36 } catch (BadImageFormatException exn) {
37 // .NET Framework 4.6.2 throws BIFE here.
43 public static int test_0_reflection_load_reference ()
45 // Check that reflection-only loading a reference assembly is okay
46 var an = new AssemblyName ("TestingReferenceAssembly");
47 var a = Assembly.ReflectionOnlyLoad (an.FullName);
48 var t = a.GetType ("X");
49 var f = t.GetField ("Y");
50 if (f.FieldType.Equals (typeof (Int32)))
55 public static int test_0_load_reference_asm_via_reference ()
57 // Check that loading an assembly that references a reference assembly doesn't succeed.
58 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
60 var a = Assembly.Load (an);
61 var t = a.GetType ("Z");
62 } catch (FileNotFoundException){
68 public static int test_0_reflection_load_reference_asm_via_reference ()
70 // Check that reflection-only loading an assembly that
71 // references a reference assembly is okay.
72 var an = new AssemblyName ("TestingReferenceReferenceAssembly");
73 var a = Assembly.ReflectionOnlyLoad (an.FullName);
74 var t = a.GetType ("Z");
75 var f = t.GetField ("Y");
76 if (f.FieldType.Equals (typeof (Int32)))
82 public static int test_0_load_reference_bytes ()
84 // Check that loading a reference assembly from a byte array for execution is an error
85 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
87 var a = Assembly.Load (bs);
88 } catch (BadImageFormatException) {
90 } catch (FileNotFoundException exn) {
91 Console.Error.WriteLine ("incorrect exn was {0}", exn);
97 public static int test_0_reflection_load_reference_bytes ()
99 // Check that loading a reference assembly from a byte
100 // array for reflection only is okay.
101 byte[] bs = File.ReadAllBytes ("./TestingReferenceAssembly.dll");
102 var a = Assembly.ReflectionOnlyLoad (bs);
103 var t = a.GetType ("X");
104 var f = t.GetField ("Y");
105 if (f.FieldType.Equals (typeof (Int32)))