[Mono-bugs] [Bug 53108][Wis] New - CustomAttributeBuilder cannot be used on types created by TypeBuilder.CreateType
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 20 Jan 2004 03:48:12 -0500 (EST)
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 malekith@pld-linux.org.
http://bugzilla.ximian.com/show_bug.cgi?id=53108
--- shadow/53108 2004-01-20 03:48:12.000000000 -0500
+++ shadow/53108.tmp.17307 2004-01-20 03:48:12.000000000 -0500
@@ -0,0 +1,104 @@
+Bug#: 53108
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details: PLD Linux
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: malekith@pld-linux.org
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: CustomAttributeBuilder cannot be used on types created by TypeBuilder.CreateType
+
+Description of Problem:
+When you use result of TypeBuilder.CreateType () to get constructor
+and later pass this to CustomAttributeBuilder then invalid assembly
+is created.
+
+Steps to reproduce the problem:
+1. Compile and run attached program, try dissassemble it with monodis
+2. You will get:
+
+** (process:6767): CRITICAL **: file metadata.c: line 797
+(mono_metadata_string_heap): assertion `index < meta->heap_strings.size' failed
+
+** ERROR **: type 0x00 not handled in do_mono_metadata_parse_type
+aborting...
+
+3. then change if (false) to if (true), recompile, run, dissasmeble, you
+will get the right results
+
+How often does this happen?
+
+Always.
+
+Additional Information:
+
+Filled bug against runtime since it seems problem with C part of reflection
+api, but i'm not sure.
+
+#v+
+using System;
+using System.Reflection;
+using System.Threading;
+using System.Reflection.Emit;
+
+
+class Bug
+{
+
+ public static void Main ()
+ {
+
+ AppDomain currentDomain = Thread.GetDomain();
+
+ AssemblyName myAsmName = new AssemblyName();
+ myAsmName.Name = "foo.dll";
+
+ AssemblyBuilder myAsmBuilder = currentDomain.DefineDynamicAssembly(
+ myAsmName, AssemblyBuilderAccess.RunAndSave);
+
+ ModuleBuilder myModBuilder =
+myAsmBuilder.DefineDynamicModule("MyModule", "foo.dll");
+
+ TypeBuilder attr_tb = myModBuilder.DefineType("MyAttribute",
+TypeAttributes.Public,
+ typeof (System.Attribute));
+
+ attr_tb.DefineDefaultConstructor (MethodAttributes.Public);
+
+ System.Type attr_t;
+
+ if (false) {
+ attr_tb.CreateType ();
+ attr_t = attr_tb;
+ } else {
+ attr_t = attr_tb.CreateType ();
+ }
+
+ TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
+TypeAttributes.Public);
+
+ Type[] ctorParams = new Type[] { };
+ ConstructorInfo classCtorInfo = attr_t.GetConstructor(ctorParams);
+
+
+ CustomAttributeBuilder myCABuilder = new CustomAttributeBuilder(
+ classCtorInfo,
+ new object[] { });
+
+ myTypeBuilder.SetCustomAttribute(myCABuilder);
+ myTypeBuilder.CreateType ();
+
+ myAsmBuilder.Save ("foo.dll");
+ }
+
+
+}
+#v-