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_parent ()
57 // Check that loading an assembly that references a reference
58 // assembly and then using a type derived from a reference
59 // assembly type doesn't succeed.
60 var an
= new AssemblyName ("TestingReferenceReferenceAssembly");
62 var a
= Assembly
.Load (an
);
63 var t
= a
.GetType ("Z");
64 } catch (FileNotFoundException
){
70 public static int test_0_load_reference_asm_via_reference_field ()
72 // Check that loading an assembly that references a reference
73 // assembly and then using a type that has a field from the
74 // reference assembly is okay as long as we don't instantiate
76 var an
= new AssemblyName ("TestingReferenceReferenceAssembly");
77 var a
= Assembly
.Load (an
);
78 var t
= a
.GetType ("HasFieldFromReferenceAssembly");
79 t
.IsSubclassOf (typeof (int));
84 public static int test_0_reflection_load_reference_asm_via_reference ()
86 // Check that reflection-only loading an assembly that
87 // references a reference assembly is okay.
88 var an
= new AssemblyName ("TestingReferenceReferenceAssembly");
89 var a
= Assembly
.ReflectionOnlyLoad (an
.FullName
);
90 var t
= a
.GetType ("Z");
91 var f
= t
.GetField ("Y");
92 if (f
.FieldType
.Equals (typeof (Int32
)))
98 public static int test_0_load_reference_bytes ()
100 // Check that loading a reference assembly from a byte array for execution is an error
101 byte[] bs
= File
.ReadAllBytes ("./TestingReferenceAssembly.dll");
103 var a
= Assembly
.Load (bs
);
104 } catch (BadImageFormatException
) {
106 } catch (FileNotFoundException exn
) {
107 Console
.Error
.WriteLine ("incorrect exn was {0}", exn
);
113 public static int test_0_reflection_load_reference_bytes ()
115 // Check that loading a reference assembly from a byte
116 // array for reflection only is okay.
117 byte[] bs
= File
.ReadAllBytes ("./TestingReferenceAssembly.dll");
118 var a
= Assembly
.ReflectionOnlyLoad (bs
);
119 var t
= a
.GetType ("X");
120 var f
= t
.GetField ("Y");
121 if (f
.FieldType
.Equals (typeof (Int32
)))