It is very difficult to answer this question without debugging the real code, but I will tell you about one problem that I encountered in the past with COM interoperability.
One possibility you might want to entertain is that the connection to the event is freed by the GC. When you attach to an event on an object that the event usually accepts a link to the attache and both objects will not be cleared by the GC, but when you have a COM object, the GC does not necessarily know about this link, and this may clear one of the objects. I came across this in the past with Office automation through .net. The way to solve this problem is to save the link to the COM object and attach to it.
For example, this is bad:
public class Foo { public Foo(ICOMObject obj) { obj.Changed += OnChanged; } private void OnChanged(object arg) { } }
This will work just fine if obj is a .net object. The event will remain connected as long as one of the objects remains a link. However, this will not work with the COM object. With a COM object, the event seems to simply stop working at some point in time, usually quite quickly.
Instead, try the following:
public class Foo { ICOMObject obj; public Foo(ICOMObject obj) { this.obj = obj; this.obj.Changed += OnChanged; } private void OnChanged(object arg) { } }
I'm not sure if this is your problem, but maybe. Good luck
source share