[Mono-bugs] [Bug 61212][Maj] New - TypeBuilder.SetParent does not work with System.Enum

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 6 Jul 2004 14:23:06 -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 rbo@acm.org.

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

--- shadow/61212	2004-07-06 14:23:06.000000000 -0400
+++ shadow/61212.tmp.15298	2004-07-06 14:23:06.000000000 -0400
@@ -0,0 +1,89 @@
+Bug#: 61212
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rbo@acm.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: TypeBuilder.SetParent does not work with System.Enum
+
+Steps to reproduce the problem:
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+class MainClass
+{
+	public static void Main(string[] args)
+	{
+		AssemblyName name = new AssemblyName();
+		name.Name = "PrintEnumTest";
+		
+		AssemblyBuilder assemblyBuilder =
+AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
+		ModuleBuilder moduleBuilder =
+assemblyBuilder.DefineDynamicModule("PrintEnumTest.exe");
+		
+		TypeBuilder enumBuilder = moduleBuilder.DefineType("Foo",
+TypeAttributes.Public|TypeAttributes.Sealed);
+		// DefineType("Foo", TypeAttributes.Public|TypeAttributes.Sealed,
+typeof(System.Enum)) works
+		enumBuilder.SetParent(typeof(System.Enum));
+		enumBuilder.DefineField("value__", typeof(int),
+
+					FieldAttributes.Public |
+
+					FieldAttributes.SpecialName |
+
+					FieldAttributes.RTSpecialName);
+
+			
+
+		FieldBuilder field = enumBuilder.DefineField("Bar", enumBuilder,
+
+								FieldAttributes.Public |
+
+								FieldAttributes.Static |
+
+								FieldAttributes.Literal);
+
+		field.SetConstant(0);
+		enumBuilder.CreateType();
+		
+		TypeBuilder type = moduleBuilder.DefineType("App");
+		MethodBuilder method = type.DefineMethod("Main",
+MethodAttributes.Public|MethodAttributes.Static, typeof(void), new Type[0]);
+		
+		ILGenerator il = method.GetILGenerator();
+		il.Emit(OpCodes.Ldc_I4, 0);
+		il.Emit(OpCodes.Box, enumBuilder);
+		il.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] {
+typeof(object) }));
+		il.Emit(OpCodes.Ret);
+		
+		MethodInfo actualMethod = type.CreateType().GetMethod("Main");		
+		actualMethod.Invoke(null, null);			 
+	}
+}
+
+
+Actual Results:
+** ERROR **: Invalid IL code at IL000a in App:Main (): IL_000a: call     
+0x0a000001 
+aborting...
+
+Expected Results:
+Bar
+
+How often does this happen? 
+Always