[Mono-bugs] [Bug 74590][Maj] New - TypeLoadException is thrown

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 13 Apr 2005 10:53:54 -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 marek.safar@seznam.cz.

http://bugzilla.ximian.com/show_bug.cgi?id=74590

--- shadow/74590	2005-04-13 10:53:53.000000000 -0400
+++ shadow/74590.tmp.28657	2005-04-13 10:53:53.000000000 -0400
@@ -0,0 +1,72 @@
+Bug#: 74590
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: marek.safar@seznam.cz               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: TypeLoadException is thrown
+
+Description of Problem:
+
+Compile following program with mcs and then run it on Microsoft Runtime.
+
+Note: Mono runtime doesn't throw such exception
+
+
+Steps to reproduce the problem:
+1. 
+
+using System;
+using System.Runtime.InteropServices;
+
+[StructLayout(LayoutKind.Explicit)]
+struct foo2 {
+}
+
+class C
+{
+    static void Main ()
+    {
+	foo2 f = new foo2 ();
+    }
+}
+
+Actual Results:
+
+Unhandled Exception: System.TypeLoadException: Could not load type foo2
+from ass
+embly t-0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null because
+field $
+PRIVATE$ was not given an explicit offset.
+   at C.Main()
+
+
+Expected Results:
+
+No exception
+
+Additional Information:
+
+It is caused by this in class.cs
+
+			//
+			// Structs with no fields need to have at least one byte.
+			// The right thing would be to set the PackingSize in a DefineType
+			// but there are no functions that allow interfaces *and* the size to
+			// be specified.
+			//
+
+			if ((Kind == Kind.Struct) && !have_nonstatic_fields){
+				TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+							 FieldAttributes.Private);
+			}