[Python.NET] AttributeError: 'MarshalByRefObject' object has no attribute ...
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:
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 - [email protected]
http://mail.python.org/mailman/listinfo/pythondotnet
RE: [Python.NET] AttributeError: 'MarshalByRefObject' object has noattribute ...
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[EMAIL PROTECTED] V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of > Martin Richard > Sent: Tuesday, December 28, 2004 3:57 PM > To: [email protected] > 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: > > > 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 - [email protected] > http://mail.python.org/mailman/listinfo/pythondotnet > _ Python.NET mailing list - [email protected] http://mail.python.org/mailman/listinfo/pythondotnet
RE: [Python.NET] AttributeError: 'MarshalByRefObject' object has noattribute ...
Thanks for the fast reply. The pseudo-cast did it. I'd wonder why trying Itoy() gave complaints about needing an argument. Rick -Original Message- From: Brian Lloyd [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 28, 2004 1:13 PM To: Martin Richard; [email protected] Subject: RE: [Python.NET] AttributeError: 'MarshalByRefObject' object has noattribute ... 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[EMAIL PROTECTED] V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of > Martin Richard > Sent: Tuesday, December 28, 2004 3:57 PM > To: [email protected] > 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: > > > 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 - [email protected] > http://mail.python.org/mailman/listinfo/pythondotnet > _ Python.NET mailing list - [email protected] http://mail.python.org/mailman/listinfo/pythondotnet
