[Mono-bugs] [Bug 29601][Wis] New - Type.GetConstructor doesn't look at type inheritance for constructor signature
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
28 Aug 2002 22:55:13 -0000
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 jonpryor@vt.edu.
http://bugzilla.ximian.com/show_bug.cgi?id=29601
--- shadow/29601 Wed Aug 28 18:55:13 2002
+++ shadow/29601.tmp.2061 Wed Aug 28 18:55:13 2002
@@ -0,0 +1,95 @@
+Bug#: 29601
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 7.3
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jonpryor@vt.edu
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Type.GetConstructor doesn't look at type inheritance for constructor signature
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+Type.GetConstructor(System.Type[]) doesn't look at the base class of types
+when looking for a matching constructor argument list.
+
+For example, if I have a class Foo:
+
+ class Foo {
+ public Foo (TextWriter writer) { /* ... */ }
+ }
+
+I'm able to pass in a subclass of `TextWriter' in C# code:
+
+ Foo f = new Foo (new StringWriter());
+
+However, I'm unable to do the "equivalent" call through (e.g.)
+Activator.CreateInstance under Mono (it works on .NET):
+
+ TextWriter w = new StringWriter();
+ Foo f = (Foo) Activator.CreateInstance(typeof(Foo),
+ new object[] {w});
+
+This is because Type.GetConstructor(Type[]) doesn't look at the base types
+of the types passed in (see the corlib/System/Activator.cs:142, which calls
+Type.GetConstructor).
+
+Steps to reproduce the problem:
+1. Compile the following code (``mcs aci.cs''). Note the commented section
+in Main(). If the commented line is used instead of the preceding line,
+the program behaves correctly. This is why I believe it to be an
+inheritence-check problem.
+
+ // file: aci.cs
+
+ using System;
+ using System.IO;
+ using System.Reflection;
+
+ public class aci
+ {
+ public static void Main ()
+ {
+ Type t = typeof(ToCreate);
+ TextWriter w = new StringWriter();
+ Type[] args = new Type[1];
+ args[0] = w.GetType();
+ // args[0] = typeof(TextWriter);
+ ConstructorInfo ci = t.GetConstructor(args);
+ if (ci == null)
+ Console.WriteLine ("couldn't find constructor!");
+ else
+ Console.WriteLine ("found constructor: {0}", ci.ToString());
+ }
+ }
+
+2. Run the resulting executable on both Linux and Windows.
+3. Note that output is different.
+
+Actual Results:
+
+On Linux, the output is:
+
+ couldn't find constructor!
+
+Expected Results:
+
+ found constructor: MonoCMethod
+
+The actual output after `constructor:' may vary; .NET has different output.
+
+How often does this happen?
+
+Always.
+
+Additional Information: