Is the .NET type of the EventManager property/field strongly typed to an IEventManager interface or is it strongly typed to MarshalByRefObject or something else? I would assume it is but can't find any documentation on the web for these APIs. Do you have an example of consuming them from C# or VB.NET?
You could also try import clr; clr.Convert(RemoteServerApi.EventManager, IEventManager)but I'd be a little surprised if that worked - it might though if there was some implicit/explicit conversion to the interface type. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Okko Willeboordse Sent: Tuesday, May 18, 2010 12:43 AM To: Discussion of IronPython Subject: Re: [IronPython] Problems with 'unbound-class-instance' method Thanks, I tried the typedproxy but failed. Maybe I got it wrong; I do; EventManager = typedproxy(RemoteServerApi.EventManager, Bosch.Vms.SDK.IEventManager) Then; EventManager.GetAllEventTypes() This results in exact the same error as; Bosch.Vms.SDK.IEventManager.GetAllEventTypes(RemoteServerApi.EventManager) Namely; TypeError: expected IEventManager, got MarshalByRefObject Se below Kind regards, import traceback import clr clr.AddReference("Bosch.Vms.SDK") import Bosch.Vms.SDK 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) # RemoteServerApi constructor instantiates an object implementing a Bosch.Vms.SDK.IEventManager # interface RemoteServerApi = Bosch.Vms.SDK.RemoteServerApi("10.119.33.241:5390<http://10.119.33.241:5390>", "Admin", "") # RemoteServerApi holds a reference to the object implementing a Bosch.Vms.SDK.IEventManager # interface. This reference is of type MarshalByRefObject. print type(RemoteServerApi.EventManager) # How to call a method of EventManager through MarshalByRefObject? print Bosch.Vms.SDK.IEventManager.GetAllEventTypes try: # Try the naive approach. RemoteServerApi.EventManager.GetAllEventTypes() except: # Obviously fails because MarshalByRefObject instances do not support reflection. # AttributeError: 'MarshalByRefObject' object has no attribute 'GetAllEventTypes' print traceback.format_exc() try: # Try the 'unbound-class-instance' method Bosch.Vms.SDK.IEventManager.GetAllEventTypes(RemoteServerApi.EventManager) except: # TypeError: expected IEventManager, got MarshalByRefObject print traceback.format_exc() try: # Okay I need a IEventManager instance Bosch.Vms.SDK.IEventManager(RemoteServerApi.EventManager) except: # TypeError: Cannot create instances of IEventManager because it is abstract print traceback.format_exc() EventManager = typedproxy(RemoteServerApi.EventManager, Bosch.Vms.SDK.IEventManager) try: print EventManager.GetAllEventTypes() except: print traceback.format_exc() # Traceback (most recent call last): # File "bvms.py", line 50, in <module> # print EventManager.GetAllEventTypes() # File "bvms.py", line 15, in __getattribute__ # return getattr(proxyType, attr).__get__(obj, proxyType) # TypeError: expected IEventManager, got MarshalByRefObject On Mon, May 17, 2010 at 10:03 PM, Dino Viehland <di...@microsoft.com<mailto:di...@microsoft.com>> wrote: Can you try the typedproxy class which is on this bug: http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=470 ? It should work to wrap the object and let you access the various attributes that you want to by calling through the type (in this case the interface type - you'd pass IEventManager for the 2nd argument to the typedproxy). From: users-boun...@lists.ironpython.com<mailto:users-boun...@lists.ironpython.com> [mailto:users-boun...@lists.ironpython.com<mailto:users-boun...@lists.ironpython.com>] On Behalf Of Okko Willeboordse Sent: Monday, May 17, 2010 9:36 AM To: users@lists.ironpython.com<mailto:users@lists.ironpython.com> Subject: [IronPython] Problems with 'unbound-class-instance' method Hello, I have some problems accessing an object. This object is instantiated by another object. This other object holds a reference to the object. This reference is of type MarshalByRefObject Obviously I cannot access the object through MarshalByRefObject. This must be done using the 'unbound-class-instance' method (please correct me if I am wrong) For this method you need to instantiate the interface type object. However the interface is abstract! How to cope with this. Please find sample code below; import traceback import clr clr.AddReference("Bosch.Vms.SDK") import Bosch.Vms.SDK # RemoteServerApi constructor instantiates an object implementing a Bosch.Vms.SDK.IEventManager # interface RemoteServerApi = Bosch.Vms.SDK.RemoteServerApi("xxxx", "xxxx", "xxxx") # RemoteServerApi holds a reference to the object implementing a Bosch.Vms.SDK.IEventManager # interface. This reference is of type MarshalByRefObject. print type(RemoteServerApi.EventManager) # How to call a method of EventManager through MarshalByRefObject? print Bosch.Vms.SDK.IEventManager.GetAllEventTypes try: # Try the naive approach. RemoteServerApi.EventManager.GetAllEventTypes() except: # Obviously fails because MarshalByRefObject instances do not support reflection. # AttributeError: 'MarshalByRefObject' object has no attribute 'GetAllEventTypes' print traceback.format_exc() try: # Try the 'unbound-class-instance' method Bosch.Vms.SDK.IEventManager.GetAllEventTypes(RemoteServerApi.EventManager) except: # TypeError: expected IEventManager, got MarshalByRefObject print traceback.format_exc() try: # Okay I need an IEventManager instance Bosch.Vms.SDK.IEventManager(RemoteServerApi.EventManager) except: # TypeError: Cannot create instances of IEventManager because it is abstract print traceback.format_exc() Okko Willeboordse _______________________________________________ Users mailing list Users@lists.ironpython.com<mailto:Users@lists.ironpython.com> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com