IronPython inheritance

October 2, 2007

So I’m starting to make some progress with my C++/managed C++/C#/IronPython desktop stack. And I’ve discovered that inheritance only works one way in the CLR. Namely, Python classes can inherit from C# bases, but Python inheritance is opaque to C# relection code. If one has a Python class derived from a C# base class and a C# interface, then C# code that attempts to use reflection to get access to that Python class will fail. To understand why, use Lutz Roeder’s Reflector tool to look inside an IronPython assembly, and compare the symbols to a C# assembly doing similar inheritance from C# base classes. The IronPython assembly introduces its own runtime infrastructure that doesn’t meet the expectations of other CLR languages in terms.

So what’s the workaround ?  As ever in integration exercises, I introduced a shim in C# that meets the expectations of the C# code while dispatching into Python.

Advertisements

2 Responses to “IronPython inheritance”


  1. I’d be interested in seeing an example of this shim – even if it is fairly specific.


  2. Can you post an example of that? I am very interested.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s