I have a COM object that is returned via GetType().Invoke(). I can can see the object properties/methods/fields but not the events:
object obj = invoker.Invoke("MethodReturnsObject");
foreach (EventInfo i in obj.GetType().GetEvents()) {
Console.WriteLine(i); // doesn't print anything
}
The library in the References has "Embed Interop Types" is set to True. Using the object browser, I can see that the the object does have the events I am interested in and they are declared public. I can also see the events in ildasm.exe inside my Interop library.
Essentially what I am trying to do is to add a new event handler to an object at runtime, after getting its EventInfo and creating a Delegate:
EventInfo info = obj.GetType().GetEvent("SomeEvent");
Delegate deleg = Delegate.CreateDelegate(info.EventHandlerType, someMethodInfo);
info.AddEventHandler(obj, deleg);
I am compiling and running on two different PCs, could it be the case that the Interop dll is not visible on the other machine? I was under impression that Embed Interop Type handles this problem, or perhaps it is necessary to use regasm/gacutil?
Aucun commentaire:
Enregistrer un commentaire