[Python.NET] AttributeError: 'MarshalByRefObject' object has noattribute ...

Brian Lloyd brian at zope.com
Tue Dec 28 22:12:31 CET 2004


Hi Martin - 

Interface types, as they appear to Python, all have a single
argument constructor that you can use to "cast" an object to 
a particular interface. 

Because System.Activator.GetObject() has a return type of 
object, the runtime returns the object as its true runtime
type to Python (which happens to be MarshalByRefObject).

So I think all you need to do is an "explicit cast":

remoteObj = System.Activator.GetObject(IToy, url)
mytoy = IToy(remoteObj)
mytoy.someMethod(...)

Hope this helps,

Brian Lloyd        brian at zope.com
V.P. Engineering   540.361.1716              
Zope Corporation   http://www.zope.com 


> -----Original Message-----
> From: pythondotnet-bounces+brian=zope.com at python.org
> [mailto:pythondotnet-bounces+brian=zope.com at python.org]On Behalf Of
> Martin Richard
> Sent: Tuesday, December 28, 2004 3:57 PM
> To: pythondotnet at python.org
> Subject: [Python.NET] AttributeError: 'MarshalByRefObject' object has
> noattribute ...
> 
> 
> This is python 2.3.
> 
> I start a toy .NET service.  This is a C-sharp executable.
> 
> In the C-sharp files, this code exists:
> 
> namespace foo
> {
>     public class Toy : MarshalByRefObject, IToy
>     ...
> }
> 
> In python, after loading an assembly, I can successfully do either:
>   from CLR.foo import Toy
>   from CLR.foo import IToy    
> 
> I can get a string for the url of the service from the config file.
> 
> I then try:
>    # using Toy also gives the same result
>    remoteObj = System.Activator.GetObject(IToy, url)  
> 
> and it returns this for remoteObj:
>   <CLR.System.MarshalByRefObject object at 0x0090D090>
> 
> If I try to invoke a method on remoteObj, I get this error:
>    AttributeError: 'MarshalByRefObject' object has no attribute
> 'methodName'.
> 
> It is almost as if the remoteObj has not been cast to the correct type
> (Itoy).  But if I do remoteObj.ToString() it returns 'foo.Toy'.
> 
> If I just try to instantiate a local instance of Toy --
>    t = Toy()
> -- this succeeds, and I can successfully invoke the method that fails on
> the remoteObj.
> 
> Any ideas why the remoteObj is failing?
> 
> Thanks,
> 
> Rick
> 
> 
> 
> 
> 
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
> 


More information about the PythonDotNet mailing list