I am writing library plugin for application which provide COM interface IPlugin. I must implement function Start(), because that application is calling my library through ProgID and giving instance of interface there.
Short sample of usage:
[ComVisible(true)]
[Guid({GUID})]
[ClassInterface(ClassInterfaceType.None)]
public class Program : IPlugin
{
[STAThread]
public void Start(IInterface myInterface)
{
var a = myInterface.GetValue();
}
}
When I am using interface in main thread, all went fine.
But, when I want to use that interface in other thread, I am getting exception:
Unable to cast COM object of type 'System.__ComObject' to interface type 'IInterface'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{GUID}' failed due to the follow error: No such interface supported
I tried "save" interface to GlobalInterfaceTable and "load" it on other thread, tried CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream, tried solution from this SO source and many others, always getting same error (using "saved" and "loaded" interface on same thread is still O.K., so I think, that I am using it right).
Maybe I am misunderstood something, I cannot give here all my attempts to solve it.
I am trying it so long, but I have no solution.
Please, if there is some more things to try, I'll be glad to sort it out.