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
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to