[Mono-bugs] [Bug 41655][Nor] New - Reflection method binding problem.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Mon, 21 Apr 2003 13:09:56 -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 tom@acquist.com.

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

--- shadow/41655	Mon Apr 21 13:09:56 2003
+++ shadow/41655.tmp.26686	Mon Apr 21 13:09:56 2003
@@ -0,0 +1,93 @@
+Bug#: 41655
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: tom@acquist.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Reflection method binding problem.
+
+Description of Problem:
+It seems as though there's a problem with method binding through 
+reflection.  While working with reflection, I came across a few cases 
+where the correct method was not being called.  In the first case, it was 
+an issue where the method was overloaded.  One of the methods took a 
+System.Object, the other took a System.Array.  When I used reflection to 
+get and call the method with a array of strings (Typed string[], not object
+[], although that shouldn't matter), it ended up calling the System.Object 
+method, rather than the System.Array one.  The other case involved a 
+method that took a plain Enum, and when called with a specific enum type, 
+it failed the method lookup.
+
+
+Steps to reproduce the problem:
+Compile and run the following:
+
+using System; 
+using System.Reflection; 
+ 
+public class BindingError 
+{ 
+ 
+public enum SimpleEnum {Dog, Cat, Bird} 
+ 
+public static void Main() 
+{ 
+   SimpleEnum simple = SimpleEnum.Bird; 
+   Console.WriteLine(simple.GetType()); 
+   Console.WriteLine(typeof(Enum).IsInstanceOfType(simple)); 
+ 
+   object[] ArgArray = new object [] {simple}; 
+   MethodInfo mi = typeof(BindingError).GetMethod("EnumPrinter", 
+Type.GetTypeArray(ArgArray)); 
+   if(mi == null) 
+   { 
+      Console.WriteLine("mi is null!"); 
+   } 
+   else 
+   { 
+      Console.WriteLine("mi is not null."); 
+      mi.Invoke(null, ArgArray); 
+   } 
+} 
+ 
+public static void EnumPrinter(Enum animal) 
+{ 
+   Console.WriteLine("Enum:"); 
+   Console.WriteLine(animal); 
+} 
+ 
+} 
+
+
+Actual Results:
+It prints:
+
+BindingError+SimpleEnum 
+True 
+mi is null! 
+
+Expected Results:
+It should output the following:
+
+BindingError+SimpleEnum 
+True 
+mi is not null. 
+Enum: 
+Bird 
+
+
+How often does this happen? 
+Every time.
+
+Additional Information:
+This occurs with Mono 0.23 on RH8.