[Mono-bugs] [Bug 73143][Nor] New - Missing System.ArgumentException in MethodBuilder.SetCustomAttribute

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 1 Mar 2005 03:56:56 -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 marek.safar@seznam.cz.

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

--- shadow/73143	2005-03-01 03:56:56.000000000 -0500
+++ shadow/73143.tmp.4186	2005-03-01 03:56:56.000000000 -0500
@@ -0,0 +1,102 @@
+Bug#: 73143
+Product: Mono: Class Libraries
+Version: 1.1
+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: Missing System.ArgumentException in MethodBuilder.SetCustomAttribute
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+
+
+Steps to reproduce the problem:
+1. compile this
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
+using System.Threading;
+
+public class Foo {
+
+	public static void Main () {
+		Type [] ctorParams = new Type[] {typeof(short) };
+			
+		ConstructorInfo classCtorInfo = 
+			typeof (MethodImplAttribute).GetConstructor (BindingFlags.Instance |
+			BindingFlags.Public, null, ctorParams, null);
+
+		CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+			classCtorInfo,
+			new object [] { (short)9999 } );
+
+
+		// preconditions
+		AppDomain currentDomain = Thread.GetDomain();
+	
+		AssemblyName myAsmName = new AssemblyName();
+		myAsmName.Name = "MyAssembly";
+
+		AssemblyBuilder myAsmBuilder = currentDomain.DefineDynamicAssembly(
+			myAsmName, AssemblyBuilderAccess.Run);
+
+		ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule("MyModule");
+
+		TypeBuilder myTypeBuilder = myModBuilder.DefineType("MyType",
+			TypeAttributes.Public);
+
+		MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod("HelloWorld",
+			MethodAttributes.Public,
+			null,
+			new Type[] { });
+
+		// end of
+	
+
+		myMethodBuilder.SetCustomAttribute(typeCABuilder);
+
+		myTypeBuilder.CreateType();
+
+	}	    
+	    
+}
+
+2. run produced exe
+
+
+Actual Results:
+
+No exception
+
+Expected Results:
+
+MS throws
+
+Unhandled Exception: System.ArgumentException: Invalid custom attribute
+provided: 'Incorrect argument value.'
+   at
+System.Reflection.Emit.TypeBuilder.InternalCreateCustomAttribute(Int32
+tkAssociate, Int32 tkConstructor, Byte[] attr, Module module, Boolean toDisk)
+   at
+System.Reflection.Emit.CustomAttributeBuilder.CreateCustomAttribute(ModuleBuilder
+mod, Int32 tkOwner)
+   at
+System.Reflection.Emit.MethodBuilder.SetCustomAttribute(CustomAttributeBuilder
+customBuilder)
+   at Foo.Main()
+
+
+Additional Information: