Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / typeload-unaligned.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class Z {
5     ~Z() {
6         Console.WriteLine("Hello, world!");
7     }
8 }
9
10 [StructLayout(LayoutKind.Explicit)]
11 public struct X {
12     [FieldOffset(0)] public short a;
13     [FieldOffset(2)] public Z z; // Unaligned reference
14 }
15
16 class Y {
17     static X test() {
18         X x = new X();
19         x.z = new Z();
20         return x;
21     }
22
23     static void test2(X x) {
24         Console.WriteLine("Object: " + x);
25     }
26
27         static void Inner () {
28         X t1 = test();
29         System.GC.Collect();
30         System.GC.Collect();
31         System.GC.WaitForPendingFinalizers();
32         test2(t1);
33         }
34
35     static int Main() {
36         try {
37                         Inner ();
38         } catch (TypeLoadException e) {
39                 Console.WriteLine ("got correct exception: {0}", e);
40                 return 0;
41         }
42         return 1;
43     }
44 }