2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / typeload-unaligned.cs
blob94de8517fdb13c767aa474c7b7d3fe0fa0742be3
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 void Inner () {
28 X t1 = test();
29 System.GC.Collect();
30 System.GC.Collect();
31 System.GC.WaitForPendingFinalizers();
32 test2(t1);
35 static int Main() {
36 try {
37 Inner ();
38 } catch (TypeLoadException e) {
39 Console.WriteLine ("got correct exception: {0}", e);
40 return 0;
42 return 1;