COMException in C # when connecting to event

I get a COM error when trying to connect to an event on a COM object. Here is the code I'm trying to execute.

COMClass a = IComClass as ComClass;
a.SomeEvent += new SomeEvent_EventHandler(MethodNameHere);

Line 2 throws a COMException with the following information:

System.Runtime.InteropServices.COME error.

Message = "Exception from HRESULT: 0x80040202"

Source = "mscorlib"

ErrorCode = -2147220990

StackTrace: in System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise (pUnkSink, Int32 & pdwCookie object)

Does anyone have any ideas why I cannot connect to a COM event or if there is a workaround for COM events?

Chris

+6
c # events interop com
source share
2 answers

The problem was that the interface for events was not logged. After I added the registry key for the event interface, this fixed the problem. I was able to get the interface identifier information using OLEViewer.exe

+4
source share

The error code you received is CONNECT_E_CANNOTCONNECT, that Googles is good. This indicates that the COM server is not happy with your attempt to subscribe to the event handler. Why is this not what you will need to find out. Getting help from the author or component supplier is almost always required.

One thing you can try is to look at the type library with Oleview.exe and find out if the event you are trying to subscribe to is on the separator marked as the default source interface. If this is not the case, try giving the object a type of dispinterface, and then subscribe to its event.

+3
source share

All Articles