2007-03-28 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mono / tests / typeload-unaligned.cs
blob5861867ec1c141691dcc334d976fee5b5588e7e9
1 using System;
2 using System.Runtime.InteropServices;
4 public class Z {
5 ~Z() {
6 Console.WriteLine("Hello, world!");
10 [StructLayout(LayoutKind.Explicit)]
11 public struct X {
12 [FieldOffset(0)] public short a;
13 [FieldOffset(2)] public Z z; // Unaligned reference
16 class Y {
17 static X test() {
18 X x = new X();
19 x.z = new Z();
20 return x;
23 static void test2(X x) {
24 Console.WriteLine("Object: " + x);
27 static int Main() {
28 try {
29 X t1 = test();
30 System.GC.Collect();
31 System.GC.Collect();
32 System.GC.WaitForPendingFinalizers();
33 test2(t1);
34 } catch (TypeLoadException e) {
35 Console.WriteLine ("got correct exception: {0}", e);
36 return 0;
38 return 1;