R – managed client of a COM server threw InvalidCastException

com-interop

I registered my very simple native COM server and my native COM client can call the COM method successfully. However, my managed COM client threw below error:

Unable to cast COM object of type 'DevicesLib.MyComClass' to interface type 'DevicesLib.IMyComInterface'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{503DDA5C-F8A2-4273-810F-3855EE0F2B78}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I used tlbimp.exe to generate a delay signed interop dll. My OS is 64 bit windows server 2008 R2.

Any idea?

Thanks
Leon

Best Answer

After I decorate [STAThreadAttribute] for the main(), it worked.

Related Topic