[IronPython] Using a C# class in IronPython

Justin Hartman justin.hartman at gmail.com
Tue Feb 16 20:59:39 CET 2010

Hi all,

I've been using IronPython (and IronRuby) for about a year for a project at
work, and I'm thrilled with them both! I encountered something strange today
and was hoping someone could shed some light on it.

I was attempting to set a property on an instance of a class which is
defined in C#, and I kept getting a SystemError indicating something about
an ambiguous match. After a pretty thorough search of my codespace, I could
not find any class names that would be conflicting or ambiguous. After
looking at the stack trace and doing a little more digging, I found out that
System.Type.GetMethod was throwing the error when searching for the
SetMember method. Then it all clicked -- my C# class has a SetMember method
(actually, 6 of them with different parameters).

So, admittedly I've never spent any time in the IronPython codebase, so this
is pure conjecture, and here's where I'm looking for some guidance. I'm
guessing that the IronPython runtime, as part of its binding magic, is
looking to see if the class has implemented SetMember to accomplish the
setting of the attribute. However, rather than looking for a method with a
particular signature, it simply looks for it by name, and fails when it
encounters more than one (an ambiguous match).

So, given that my C# class has a good reason for implementing the SetMember
method (because it makes sense in our application domain), what's an
IronPython user to do? Do I have to just rename my SetMember method to
something else? Should the IronPython runtime do a more specific lookup for
SetMember, maybe with a specific signature?

Thanks in advance,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100216/67043d37/attachment.html>

More information about the Ironpython-users mailing list