[Mono-bugs] [Bug 79092][Wis] Changed - type.InvokeMethod fails when using out parameters

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Aug 17 11:09:34 EDT 2006


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 robertj at gmx.net.

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

--- shadow/79092	2006-08-17 06:23:46.000000000 -0400
+++ shadow/79092.tmp.28959	2006-08-17 11:09:34.000000000 -0400
@@ -1,14 +1,14 @@
 Bug#: 79092
 Product: Mono: Class Libraries
 Version: unspecified
-OS: 
+OS: unknown
 OS Details: Fedora 4
-Status: NEW   
-Resolution: 
-Severity: 
+Status: RESOLVED   
+Resolution: NOTABUG
+Severity: Unknown
 Priority: Wishlist
 Component: System
 AssignedTo: mono-bugs at ximian.com                            
 ReportedBy: ccirstea at saguaronet.ro               
 QAContact: mono-bugs at ximian.com
 TargetMilestone: ---
@@ -99,6 +99,61 @@
 How often does this happen? 
 Always
 
 Additional Information:
 
 Using Mono 1.1.16.1, both mcs and gmcs compilers
+
+------- Additional Comments From robertj at gmx.net  2006-08-17 11:09 -------
+You cannot invoke methods with out params this way.
+This is by design and it's not a bug.
+
+Try something like this instead:
+
+        /// <summary>
+        /// Invokes the named method of the specified target object.
+        /// </summary>
+        /// <param name="target">The target object</param>
+        /// <param name="methodName">The method name</param>
+        /// <param name="byRef">Specifies which arguments must be
+passed by reference.</param>
+        /// <param name="args">The method arguments</param>
+        /// <returns></returns>
+        /// <example>
+        /// <code>
+        /// //
+        /// // calling method string Test(string arg1, ref object arg2);
+        /// //
+        /// SomeObject x = new SomeObject();
+        /// string s = (string) Introspect.InvokeMethod(o, "Test",
+        ///     new bool[] {false, true}, new object[] {"hi!", x});
+        /// </code>
+        /// </example>
+        public static object InvokeMethod(object target, string
+methodName, bool[] byRef, object[] args)
+        {
+            if (byRef.Length != args.Length)
+                throw new ArgumentException("Length of byRef and args
+must match.", "byRef, args");
+
+            ParameterModifier[] mods = new
+ParameterModifier[byRef.Length];
+
+            for (int i = 0; i < byRef.Length; i++) 
+            {
+                ParameterModifier m = new ParameterModifier(1);
+                m[0] = byRef[i];
+                mods[i] = m;
+            }
+
+            return target.GetType().InvokeMember(
+                methodName,
+                BindingFlags.InvokeMethod,
+                null,
+                target,
+                args,
+                mods,
+                null,
+                null
+                );
+        }
+


More information about the mono-bugs mailing list