[Mono-bugs] [Bug 41974][Cos] New - Illegal ArgumentNullException throw for the dynamic creation of object

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Sat, 26 Apr 2003 15:05:43 -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 gfr@skynet.be.


--- shadow/41974	Sat Apr 26 15:05:43 2003
+++ shadow/41974.tmp.26156	Sat Apr 26 15:05:43 2003
@@ -0,0 +1,75 @@
+Bug#: 41974
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 8.0
+OS Details: 
+Status: NEW   
+Severity: 001 One hour
+Priority: Cosmetic
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: gfr@skynet.be               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+Summary: Illegal ArgumentNullException throw for the dynamic creation of object 
+When invoking the creation of one object by a reflection way. I Call
+  System.Type type = typeof (MyClass);
+  type.InvokeMember (null,
+     System.Reflection.BindingFlags.Default | 
+     null,
+     null,
+     constructorArguments);
+This call is propagate until the class mcs/class/corlib/System/MonoType.cs
+as we could see inside the exception stack trace :
+  Unhandled Exception: System.ArgumentNullException: Argument cannot be 
+  Parameter name: name
+  in <0x001c2> 00 System.MonoType:InvokeMember 
+  in <0x0002f> 00 System.Type:InvokeMember 
+The method InvokeMember does not allow a null value for the method call
+at the parameter called 'name' but when we use the Binding flags for the 
+creation, this method must not throw a ArgumentNullException. 
+The argument check value must be place below after the following block of 
+code and not at the start of the method in order to be compliant with the 
+Microsoft Corlib.
+  if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
+    /* the name is ignored */
+    invokeAttr |= BindingFlags.DeclaredOnly;
+    ConstructorInfo[] ctors = GetConstructors (invokeAttr);
+    object state = null;
+    MethodBase ctor = binder.BindToMethod (invokeAttr, ctors, ref args, 
+modifiers, culture, namedParameters, out state);
+    if (ctor == null)
+      throw new MissingMethodException ();
+    object result = ctor.Invoke (target, invokeAttr, binder, args, 
+    binder.ReorderArgumentArray (ref args, state);
+    return result;
+  }
+We could remark that the name could have a null value. Moreover, when we 
+enter inside the 'Then' sequence we always return from the InvokeMember 
+etheir by an exception or by a return instruction.
+Now, i've call the Type.InvokeMember (...) with a System.String.Empty 
+value for the name argument to work around this problem. But it could be 
+annoying for some program porting to find this problem except if 
+a 'porting how-to' exist.
+Best regards,