[IronPython] CLR class constructors and arrays

Michael Foord fuzzyman at voidspace.org.uk
Mon Jul 30 22:56:15 CEST 2007


Hello Eric,

Interestingly it works with:
pc = ParamCall(('a', 'b', 'c'))

passing a tuple instead of an array.

Still looks like a bug.

Michael
http://www.ironpython.info/

Eric Rochester wrote:
> Hi,
>
> I've been using IronPython for a few months now, and I'm really 
> enjoying it. Thanks for all the hard work that's gone into it.
>
> I recently ran across an issue, and I wondered if anyone else has seen 
> it. I think it's probably a bug, but I couldn't find a bug report, 
> either.
>
> Basically, if there is a CLR class that takes an array as its only 
> constructor argument, IronPython always tries to call it using params. 
> For example, if I compile this to ParamCall.dll:
>
>     // ParamCall.cs
>
>     using System;
>
>     namespace ParamCall
>     {
>         public class ParamCall
>         {
>             private string[] args;
>
>             public ParamCall(string[] args)
>             {
>                 this.args = args;
>             }
>
>             public string Joined()
>             {
>                 return String.Join(",", args);
>             }
>         }
>     }
>
>
> And I call it using this script:
>
>     # paramcall.py
>
>     import clr
>     clr.AddReference('ParamCall')
>
>     from ParamCall import ParamCall
>     from System import Array
>
>     args = Array[str]( ['a', 'b', 'c'] )
>     print 'args =', args
>
>     print 'creating ParamCall object:'
>     pc = ParamCall(args)
>     print 'pc.Joined() =>', pc.Joined()
>
>     print
>
>
> I get these results.
>
>     C:\home\eric\src\ase\Lse.Net>IronPython\ipy paramcall.py
>     args = System.String[]('a', 'b', 'c')
>     creating ParamCall object:
>     Traceback (most recent call last):
>       File C:\home\eric\src\ase\Lse.Net\paramcall.py, line 7, in
>     Initialize
>       File , line 0, in __import__##4
>       File C:\home\eric\src\ase\Lse.Net\ParamCall.py, line 15, in
>     Initialize
>       File , line 0, in NonDefaultNew##54
>     TypeError: ParamCall() takes exactly 1 argument (3 given)
>
>
> I have also tried wrapping the arguments in a tuple and calling it 
> like ParamCall( *(args,) ), but the results are the same.
>
> If anyone has any suggestions for work-arounds or clues as to what I'm 
> doing wrong, I'd be glad to hear them.
>
> Thanks,
>
> -- 
> Eric Rochester
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list