[Mono-bugs] [Bug 74798][Nor] New - mono/.NET behavior difference with "union" structs
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 2 May 2005 12:09:25 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by danw@novell.com.
http://bugzilla.ximian.com/show_bug.cgi?id=74798
--- shadow/74798 2005-05-02 12:09:25.000000000 -0400
+++ shadow/74798.tmp.8440 2005-05-02 12:09:25.000000000 -0400
@@ -0,0 +1,41 @@
+Bug#: 74798
+Product: Mono: Runtime
+Version: 1.1
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: danw@novell.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: mono/.NET behavior difference with "union" structs
+
+I tried creating a struct basically like this:
+
+ [StructLayout (LayoutKind.Explicit)]
+ public struct Foo {
+ [FieldOffset (0)] public int foo;
+ [FieldOffset (0)] public EventHandler bar;
+ }
+
+which worked fine until I tried using it as the key in a hash table,
+at which point the program crashed with an unhandled exception because
+it was trying to hash the int value as though it was an EventHandler.
+Overriding Foo's GetHashCode() method to only look at the int field made
+everything work fine.
+
+I went to compare this against .NET's behavior though, and discovered
+that .NET won't even load the assembly:
+
+ An unhandled exception of type 'System.TypeLoadException' occurred
+ in foo.exe
+
+ Additional information: Could not load type Foo from assembly 0
+ because it contains an object field at offset 0 that is incorrectly
+ aligned or overlapped by a non-object field.