[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.

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

--- 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   
+Resolution: 
+Severity: 001 One hour
+Priority: Cosmetic
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: gfr@skynet.be               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+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 | 
+System.Reflection.BindingFlags.CreateInstance,
+     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 
+null
+  Parameter name: name
+  in <0x001c2> 00 System.MonoType:InvokeMember 
+(string,System.Reflection.BindingFlags,System.Reflection.Binder,object,obj
+ect[],System.Reflection.ParameterModifier
+[],System.Globalization.CultureInfo,string[])
+  in <0x0002f> 00 System.Type:InvokeMember 
+(string,System.Reflection.BindingFlags,System.Reflection.Binder,object,obj
+ect[])
+
+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, 
+culture);
+    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,
+Gilles