[Mono-bugs] [Bug 60411][Nor] New - CustomAttributeBuilder ctor crash

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 18 Jun 2004 06:57:24 -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=60411

--- shadow/60411	2004-06-18 06:57:24.000000000 -0400
+++ shadow/60411.tmp.12848	2004-06-18 06:57:24.000000000 -0400
@@ -0,0 +1,113 @@
+Bug#: 60411
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: marek.safar@seznam.cz               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: CustomAttributeBuilder ctor crash
+
+My test case:
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Threading;
+
+public class FooAttribute : Attribute 
+{
+	public char [] Separator;
+}
+
+
+public class C
+{
+	public static void CtorFourTest ()
+	{
+		AssemblyName asmName = new AssemblyName ();
+		asmName.Name = "TestAssembly.dll";
+
+		AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
+			asmName , AssemblyBuilderAccess.Run);
+
+		ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
+		TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
+			TypeAttributes.Public);
+
+		Type [] ctorParams = new Type [] { };
+		ConstructorInfo classCtorInfo = typeof (FooAttribute).GetConstructor
+(ctorParams);
+
+		CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(
+			classCtorInfo,
+			new object [] { },
+			new PropertyInfo [0],
+			new object [0],
+			typeof(FooAttribute).GetFields (),
+			new object [] { new char [] { 'F' } }
+		); 
+
+		typeBuilder.SetCustomAttribute (typeCABuilder);
+
+		// create the type
+		Type myType = typeBuilder.CreateType ();
+
+		//Now check for the validity of the attributes.
+		object testInstance = Activator.CreateInstance (myType);
+
+		//check the validity of the attribute associated with Print method 
+		object [] customAttrs = myType.GetCustomAttributes (false);
+
+		//Custom Attributes of TestType
+		FooAttribute attr = customAttrs [0] as FooAttribute;
+		Console.WriteLine (attr.Separator);
+	}
+
+	public static void Main ()
+	{
+		CtorFourTest ();
+	}
+}
+
+
+Actual Results:
+
+I get this exception
+
+Unhandled Exception: System.NullReferenceException: Object reference not set to
+an instance of an object
+in (unmanaged) (wrapper managed-to-native)
+System.Reflection.Emit.CustomAttribut
+eBuilder:GetBlob
+(System.Reflection.Assembly,System.Reflection.ConstructorInfo,o
+bject[],System.Reflection.PropertyInfo[],object[],System.Reflection.FieldInfo[],
+object[])
+in <0x00004> (wrapper managed-to-native)
+System.Reflection.Emit.CustomAttributeB
+uilder:GetBlob
+(System.Reflection.Assembly,System.Reflection.ConstructorInfo,obj
+ect[],System.Reflection.PropertyInfo[],object[],System.Reflection.FieldInfo[],ob
+ject[])
+in <0x00c0b> System.Reflection.Emit.CustomAttributeBuilder:Initialize
+(System.Re
+flection.ConstructorInfo,object[],System.Reflection.PropertyInfo[],object[],Syst
+em.Reflection.FieldInfo[],object[])
+in <0x00028> System.Reflection.Emit.CustomAttributeBuilder:.ctor
+(System.Reflect
+ion.ConstructorInfo,object[],System.Reflection.PropertyInfo[],object[],System.Re
+flection.FieldInfo[],object[])
+in <0x0029c> C:CtorFourTest ()
+in <0x00007> C:Main ()
+
+Expected Results:
+
+Program should print: F