[Mono-bugs] [Bug 694112] New: System.Type.GetConstructor(Type.EmptyTypes) returns variadic constructors whose only parameter is a params-argument

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon May 16 15:02:09 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=694112

https://bugzilla.novell.com/show_bug.cgi?id=694112#c0


           Summary: System.Type.GetConstructor(Type.EmptyTypes) returns
                    variadic constructors whose only parameter is a
                    params-argument
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: 64bit
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: florianhaag at freenet.de
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.2.10)
Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729; .NET4.0E)

System.Type.GetConstructor(System.Type[]) can be used to retrieve a constructor
with the specified signature.

When passing an empty array as the argument, the result should be a
parameterless constructor, or null, if the considered type doesn't offer one.
This is what the .NET implementation behaves like.

The Mono implementation, however, sometimes returns constructors with
parameters: If the only parameter of the constructor is a params-argument, i.e.
if the constructor may be passed zero or more arguments, Mono's GetConstructor
implementation will return that constructor.

The problem: When you call GetConstructor for a specified number of parameters
(here: 0, possibly w.l.o.g.), you expect the returned ConstructorInfo instance
to have exactly that number of parameters, so you can call
ConstructorInfo.Invoke(Type[]) with an array of the same size. If there was
however a params-argument, Invoke(Type[]) will crash because you have supplied
one argument less than required.

Reproducible: Always

Steps to Reproduce:
Compile the attached file and invoke the resulting executable using Mono (=>
"Actual Results").

Invoke it using .NET to compare the results (=> "Expected Results").
Actual Results:  
Mono output:

Type: MainClass+TestClass1
Total number of constructors: 1
Type.EmptyTypes: 0 parameter(s)
ctor(null) => Object created. ToString() returns First Test Class.
ctor(new object[0]) => Object created. ToString() returns First Test Class.
ctor(new int[0]) => Object not created.
new Type[] { typeof(int[]) }: null
Type: MainClass+TestClass2
Total number of constructors: 1
Type.EmptyTypes: 1 parameter(s)
ctor(null) => Object not created.
ctor(new object[0]) => Object not created.
ctor(new int[0]) => Object created. ToString() returns Second Test Class.
new Type[] { typeof(int[]) }: 1 parameter(s)
ctor(null) => Object not created.
ctor(new object[0]) => Object not created.
ctor(new int[0]) => Object created. ToString() returns Second Test Class.

The 10th line illustrates the problem: I requested a parameterless constructor,
but the returned constructor actually expects one parameter. Likewise, invoking
the constructor without any parameters in line 11 and 12 fails, while passing
an (empty) array in line 13 works.

Expected Results:  
NET output:

Type: MainClass+TestClass1
Total number of constructors: 1
Type.EmptyTypes: 0 parameter(s)
ctor(null) => Object created. ToString() returns First Test Class.
ctor(new object[0]) => Object created. ToString() returns First Test Class.
ctor(new int[0]) => Object not created.
new Type[] { typeof(int[]) }: null
Type: MainClass+TestClass2
Total number of constructors: 1
Type.EmptyTypes: null
new Type[] { typeof(int[]) }: 1 parameter(s)
ctor(null) => Object not created.
ctor(new object[0]) => Object not created.
ctor(new int[0]) => Object created. ToString() returns Second Test Class.

This works as expected: Asking for a parameterless constructor only returns a
truly parameterless constructor (line 3; null is returned in line 10 because
TestClass2 doesn't have a parameterless constructor).

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list