2 // load-exceptions.cs: Tests for loading missing types/methods/fields from IL
7 using System
.Reflection
;
9 class Miss1
: Missing
.Foo1
{
13 public class Foo
: Missing
.Foo1
{
17 public class Tests
: LoadMissing
{
19 public delegate void TestDel ();
21 internal static int check_type_load (TestDel d
) {
25 catch (TypeLoadException ex
) {
26 //Console.WriteLine (ex.TypeName);
27 //Console.WriteLine (ex);
34 internal static int check_missing_method (TestDel d
) {
38 catch (MissingMethodException ex
) {
39 //Console.WriteLine (ex);
46 internal static int check_file_not_found (TestDel d
){
49 } catch (FileNotFoundException ex
){
55 internal static int check_missing_field (TestDel d
) {
59 catch (MissingFieldException ex
) {
60 //Console.WriteLine (ex);
72 public static int test_0_call () {
73 return check_missing_method (new TestDel (missing_call
));
76 public static int test_0_jmp () {
77 return check_missing_method (new TestDel (missing_jmp
));
80 public static int test_0_ldftn () {
81 return check_missing_method (new TestDel (missing_ldftn
));
85 // Object model instructions
88 public static int test_0_box () {
93 public static int test_0_callvirt () {
94 return check_missing_method (new TestDel (missing_callvirt
));
97 public static int test_0_castclass () {
98 return check_type_load (new TestDel (missing_castclass
));
101 public static int test_0_cpobj () {
102 return check_type_load (new TestDel (missing_cpobj
));
105 public static int test_0_missing_type_on_parameter () {
106 return check_type_load (new TestDel (missing_external_type_reference_on_parameter
));
108 public static int test_0_initobj () {
109 return check_type_load (new TestDel (missing_initobj
));
112 public static int test_0_isinst () {
113 return check_type_load (new TestDel (missing_isinst
));
116 public static int test_0_ldelem () {
121 public static int test_0_ldelema () {
126 public static int test_0_ldfld () {
127 return check_missing_field (new TestDel (missing_ldfld
));
130 public static int test_0_ldflda () {
131 return check_missing_field (new TestDel (missing_ldflda
));
134 public static int test_0_ldobj () {
139 public static int test_0_ldsfld () {
140 return check_missing_field (new TestDel (missing_ldsfld
));
143 public static int test_0_ldsflda () {
144 return check_missing_field (new TestDel (missing_ldsflda
));
147 public static int test_0_ldtoken_type () {
148 return check_type_load (new TestDel (missing_ldtoken_type
));
151 public static int test_0_ldtoken_method () {
152 return check_missing_method (new TestDel (missing_ldtoken_method
));
155 public static int test_0_ldtoken_field () {
156 return check_missing_field (new TestDel (missing_ldtoken_field
));
159 public static int test_0_ldvirtftn () {
160 return check_missing_method (new TestDel (missing_ldvirtftn
));
163 public static int test_0_mkrefany () {
168 public static int test_0_newarr () {
169 return check_type_load (new TestDel (missing_newarr
));
172 public static int test_0_newobj () {
173 return check_missing_method (new TestDel (missing_newobj
));
176 public static int test_0_refanyval () {
177 return check_type_load (new TestDel (missing_refanyval
));
180 public static int test_0_sizeof () {
181 return check_type_load (new TestDel (missing_sizeof
));
184 public static int test_0_stelem () {
189 public static int test_0_stfld () {
190 return check_missing_field (new TestDel (missing_stfld
));
193 public static int test_0_stobj () {
198 public static int test_0_stsfld () {
199 return check_missing_field (new TestDel (missing_stsfld
));
202 public static int test_0_unbox () {
203 return check_type_load (new TestDel (missing_unbox
));
206 public static int test_0_unbox_any () {
207 return check_type_load (new TestDel (missing_unbox_any
));
211 // Bummer: we regressed! I should have put this before
212 public static int test_0_missing_assembly_in_fieldref () {
213 return check_file_not_found (new TestDel (missing_assembly_in_fieldref
));
217 // FIXME: the corrent exception here is FileNotFoundException
218 public static int test_0_missing_assembly_in_call () {
219 return check_type_load (new TestDel (missing_assembly_in_call
));
222 public static int test_0_missing_assembly_in_newobj () {
223 return check_type_load (new TestDel (missing_assembly_in_newobj
));
226 public static int test_0_missing_delegate_ctor_argument () {
227 return check_type_load (new TestDel (missing_delegate_ctor_argument
));
231 // Missing classes referenced from metadata
234 public static int test_0_missing_local () {
238 catch (TypeLoadException ex
) {
241 /* MS.NET doesn't throw an exception if a local is not found */
245 //Regression test for #508532
246 public static int test_0_assembly_throws_on_loader_error ()
249 Assembly asm
= Assembly
.Load ("load-missing");
250 asm
.GetType ("BrokenClass", false);
252 } catch (TypeLoadException
) {}
256 public static int test_0_bad_method_override1 ()
259 BadOverridesDriver
.bad_override1 ();
261 } catch (TypeLoadException
) {}
265 public static int test_0_bad_method_override2 ()
268 BadOverridesDriver
.bad_override2 ();
270 } catch (TypeLoadException
) {}
274 public static int test_0_bad_method_override3 ()
277 BadOverridesDriver
.bad_override3 ();
279 } catch (TypeLoadException
) {}
283 public static int test_0_bad_method_override4 ()
286 BadOverridesDriver
.bad_override4 ();
288 } catch (TypeLoadException
) {}
292 public static void missing_outer () {
293 new Missing
.Foo1
.InnerFoo ();
296 //Regression test for #508487
297 public static int test_0_missing_outer_type_in_typeref () {
298 return check_type_load (new TestDel (missing_outer
));
302 public static int test_0_exception_while_jitting_cctor () {
305 } catch (TypeInitializationException
) {
313 public static void missing_parent () {
317 public static int test_0_missing_parent () {
318 return check_type_load (new TestDel (missing_parent
));
322 public static int test_0_missing_nested () {
323 if (typeof (Miss2
).GetNestedTypes ().Length
!= 0)
328 public static int test_0_reflection_on_field_with_missing_type () {
329 var t
= typeof (BadOverridesDriver
).Assembly
.GetType ("FieldWithMissingType");
330 foreach (var f
in t
.GetFields (BindingFlags
.Public
| BindingFlags
.Static
)) {
332 Console
.WriteLine (f
.Name
);
335 } catch (TypeLoadException
) {
343 public static int Main () {
344 return TestDriver
.RunTests (typeof (Tests
));