[IronPython] remoting from IronPython

Dino Viehland dinov at exchange.microsoft.com
Thu Jun 15 08:19:33 PDT 2006


Ok, I've looked into this some more now...  Turns out that all my previous advice was useless.

The problem here is actually that MarshalByRefObject's will happily cast to any interface you ask for.  For example in C# if you try and cast some random MBR to IComparable, it works.  Only when you call it does it fail (likewise doing a Console.WriteLine fails because the MBR isn't an IFormattable, but it seems to say it is).

The work around for this is to always call through the known-type, rather than calling through the object.  For example if your type is Test you do:

Test.HelloWorld(myObj)

Instead of:

myObj.HelloWorld()

and we'll do the right thing.  Here's a helper class to provide a wrapper so you don't need to do this all the time:

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

just do:

test = typedproxy(System.Activator.GetObject(RemoteTest, 'http://localhost:8000/RemoteTest'), RemoteTest)

then you can do:

test.HelloWorld()

and it'll all work fine.

I suspect that we won't be fixing this for IP 1.0, because there isn't really much we can do automatically on your behalf.  It might be worth including a built-in typedproxy class.  This hasn't been the only time calling through the type instead of the instance is necessary (for example it can be necessary w/ explicit interface implementations that collide w/ other methods in the type).  Does anyone else have any thoughts on the usefulness of this?


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Wednesday, June 14, 2006 5:16 PM
To: Discussion of IronPython
Subject: Re: [IronPython] remoting from IronPython

Are you remoting to another process, or to another app domain?  Does the other process have access to IronPython.dll ?

One thing you might want to try doing is installing IronPython into the GAC (assuming this is beta 7, or if you re-built w/ the Signed Release or Signed Debug build modes w/ your own key), and then try this.   This would ensure that the type would be loadable in both app domains, even if the files aren't readily available.  It's also go a long way to making sure we're getting loaded into the correct loader context.

Another helpful debugging tip for debugging CLR interaction issues is running IronPythonConsole w/ the -X:ExceptionDetail option.  That will get you a much better stack trace about where the issue is occurring.

I'd need to get some time to setup a repro to be able to say much more about this - but it's definitely something we'll want to make works (or understand why it doesn't if it's impossible to make work) before 1.0.


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ralph Soons
Sent: Wednesday, June 14, 2006 6:57 AM
To: users at lists.ironpython.com
Subject: Re: [IronPython] remoting from IronPython

Hi again,

I searched a little further and found out the following:

When using remoting - server activated objects:
and s = NameSpace.RemoteObject()
I discovered the "Cannot load type 'clr:IronPython.Runtime.IDynamicObject,
IronPython...." exception occurs on the following location:
namespace: IronPython.Runtime
file: Ops.cs
funtion: public static DynamicType GetDynamicType(object o) {
Line: if (dt != null) return dt.GetDynamicType(); (line 562)

during debuging I discovered that 'object o' (input of the function) is of type MarshalByRefObject so I guess its my remote object. The first line in the function is IDynamicObject dt = o as IDynamicObject;. dt is not null after executing this line. This is strange because its being casted to IDynamicObject, which isn't implemented by my remote object. There after when the next line is executed if (dt != null) return dt.GetDynamicType();, the exception occurs.
Can anyone tell me why this is going wrong?

I also tried to use client activated objects. In that case the remoting call is working correctly.

Thanks for your help again.
Ralph Soons

>From: "Ralph Soons" <ralph.soons.asml at hotmail.com>
>Reply-To: Discussion of IronPython <users at lists.ironpython.com>
>To: users at lists.ironpython.com
>Subject: [IronPython] remoting from IronPython
>Date: Wed, 14 Jun 2006 09:09:57 +0200
>
>Hi all,
>
>I am trying to call an function on a server via remoting, using IronPython.
>First I created a c# server/client to test everything.
>
>In the C# client I have the following code:
>RemotingConfiguration.Configure("executablename.exe.config", false);
>RemoteObject object = new RemoteObject(); I can now reach my remote
>object from the client.
>
>There after I used IronPython to do the same in python:
>System.Runtime.Remoting.RemotingConfiguration.Configure("IronPythonTest
>.exe.config",
>0)
>s = NameSpace.RemoteObject()
>I now get the following error:
>Cannot load type 'clr:IronPython.Runtime.IDynamicObject, IronPython
>
>I also tried:
>s = System.Activator.GetObject(
>System.Type.GetType(NameSpace.RemoteObject),
>"http://localhost:9000/mytest" )
>I then get this error:
>#  File , line 0, in GetObject##10
>#  File mscorlib, line unknown, in GetObject
>#SystemError: Trying to create a proxy to an unbound type.
>
>Can someone tell me if its possible to use remoting from IronPython or
>does any one has an idea what I am doing wrong?
>
>Many thanks!
>Ralph Soons
>
>_________________________________________________________________
>Play online games with your friends with MSN Messenger
>http://www.join.msn.com/messenger/overview
>
>_______________________________________________
>users mailing list
>users at lists.ironpython.com
>http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_________________________________________________________________
MSN Search, for accurate results! http://search.msn.nl

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


More information about the users mailing list