[IronPython] Problem inheriting from C# abstract base class with overloaded constructors
dinov at microsoft.com
Thu Dec 4 03:19:38 CET 2008
This is bug #20021 - http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=20021
You should be able to declare the ctor public. It shouldn't be an error to do that but you'll get an FxCop warning if you run FxCop.
I checked a fix for this in today into the Main branch (which is 2.1). I think that should show up on CodePlex tonight or tomorrow if you're willing to build IronPython from source. If not we'll definitely fix this in 2.0.1 if we don't spin a new build for 2.0 which would also likely include the fix.
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Mark Traudt
> Sent: Wednesday, December 03, 2008 5:49 PM
> To: users at lists.ironpython.com
> Subject: [IronPython] Problem inheriting from C# abstract base class
> with overloaded constructors
> If I create an abstract base class in C# that has overloaded
> and then subclass from this in IronPython, then I am unable to call the
> non-default base class constructor from the __new__ method in the
> If I try, I get the result shown after the code sample.
> Interestingly, if I change the base class to not be abstract and to
> public constructors (both changes are required) then my IronPython
> works fine.
> Is this a bug? If not, then am I doing something wrong, or is this not
> supported for some reason?
> I reproduced this with IronPython-1.1.2 and IronPython-2.0B5.
> *** OneOff.cs ***
> namespace Test
> public abstract class Foo
> protected Foo()
> protected Foo(int a)
> a_ = a;
> public override string ToString()
> return "Foo: " + a_;
> private int a_;
> *** OneOff.py ***
> import clr
> from Test import *
> class Bar(Foo):
> def __new__ (cls, a=0):
> return Foo.__new__(cls, a)
> print Bar()
> print Bar(42)
> *** Results ***
> Traceback (most recent call last):
> File C:\dev\OneOff\IronPython\OneOff.py, line 10, in
> File C:\dev\OneOff\IronPython\OneOff.py, line 8, in
> File , line 0, in DefaultNew##15
> TypeError: default __new__ does not take parameters
> View this message in context: http://www.nabble.com/Problem-inheriting-
> Sent from the IronPython mailing list archive at Nabble.com.
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users