Unable to cast COM object error when calling COM from .NET C# worker thread

I’m having an issue calling a COM object function from .NET C# client program. The COM object is written in C++ unmanaged. The problem only appears when I’m calling from a worker thread, it works fine if I call it from the UI thread. This is the error:

Unable to cast COM object of type ‘gvAgileFileReaderLib.gvAgileFileReaderClass’ to interface type ‘gvAgileFileReaderLib.IgvMpiRead’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{616B5C39-C7FB-4C8C-85D4-27559DD83304}’
failed due to the following error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

I have tried the following methods but all of them fails:

1) Create the COM object on UI thread, and call its function via its interface (IgvMpiRead) in the worker thread

2) Create the COM object on the worker thread & access its function from worker thread

3) Tried with worker thread set to STA & MTA

I need to use the COM function is a worker thread to prevent a long processing from holding up my UI, but it just doesn’t work when I try to call the COM function inside the worker thread.

The weird thing is that doing the same from a unmanaged C++ client works fine (I can create the com object on UI, and then call its function from worker thread). Is this problem caused by interop issues? I’m using the interop that Visual Studio 2010 creates
for me when I add reference to the C++ COM object.






hi Eric,Thanks for the reply. We just found out that the issue  was caused  by the manifest file that we embbed into the C# program  (for reg-free COM). The unmanaged  C++ client  didn’t have this problem  as I was using normal dll registration method when testing with

Hi,May I know the issue  status? please feel free to let us know if you have any concern.