Subject: Registering events dynaically with a remote object
Posted By: steven43126 Post Date: 2/21/2006 6:27:07 AM
Ok where do i begin...
well i am trying to come up with a solution to allow me to register event handlers with an event dynamically. Consider the following code

if (aEvent.Name.CompareTo("getFilesCalledEvent") == 0)
{
Delegate myDel =Delegate.CreateDelegate(aEvent.EventHandlerType,
this, "EventCalled");
aEvent.AddEventHandler(this, myDel);
}

As far as im concerned this should register the method EventCalled contained in the running instance of the object pointed to by (this).
When executed i get the exception "Object does not match target type", when i call the AddEventHandler Method.

As far as i can assume this is because im using remoting, see aEvent is actually an EventInfo type returned from a remote object. So im guessing the delegate im passing in is actually trying to point to a local instance. But im registering it with a remote object, so when it tries to call back to the class that holds EventCalled it does not know to go through the remoting framework? Ie The object is pointing to does not exist in the context of the remote object.

This is my best guess anyone who can help your a godsend!


Go to topic 40360

Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360
Return to index page 359
Return to index page 358
Return to index page 357
Return to index page 356
Return to index page 355