[IronPython] .NET remoting with IronPython

Dino Viehland dinov at exchange.microsoft.com
Wed Sep 20 17:36:27 CEST 2006


This is a known issue - an easier work around is to create a typed proxy in Python that holds onto the instance & the interface type and does calls through the interface type passing the instance as the 1st parameter.  Bug 470 has the workaround code, http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=470, but it is:

class typedproxy(object):
      __slots__ = ['obj', 'proxyType']
      def __init__(self, obj, proxyType):
        self.proxyType = proxyType
        self.obj = obj
      def __getattribute__(self, attr):
        proxyType = object.__getattribute__(self, 'proxyType')
        obj = object.__getattribute__(self, 'obj')
        return getattr(proxyType, attr).__get__(obj, proxyType)

The issue here is that in .NET doing a cast of an MBR to an interface type always succeeds - and internally we're doing lots of casts against interfaces.


From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Russell Lear
Sent: Wednesday, September 20, 2006 6:55 AM
To: users at lists.ironpython.com
Subject: [IronPython] .NET remoting with IronPython

I'm trying to access a service that uses .NET remoting using IronPython.  I have a C# interface, something like:

    interface IUserDB { ...
        MyUser GetUser(string id);
        ....};

I've tried to get a remoted instance of that interface using the following python:
    t = a.GetType("IUserDB")   # This works
    db = System.Runtime.Remoting.RemotingServices.Connect(t, dbServerURL)

But if I try to do anything with db, I get:
SystemError: Type 'IronPython.Runtime.ModuleScope' in Assembly 'IronPython, Version=1.0.60816.1877, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' is not marked as serializable.

I get the same error if I instantiate the remoted object in C# and then try to do anything with it in Python.  My work around is to create a proxy that wraps the remote object in a class that implements IUserDB by passing the calls directly to the wrapped remote object.  Works, but a little ugly.  Any thoughts?

Thanks,
Russell.



More information about the Ironpython-users mailing list