[IronPython] CLR class constructors and arrays

Eric Rochester erochest at gmail.com
Mon Jul 30 22:36:56 CEST 2007


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070730/75e79de0/attachment.html>


More information about the Ironpython-users mailing list