Interop COM object throws an InvalidCastException in one project, but not in another

I have a COM object that I imported into my C # test solution. Everything is working fine and continues to do so.

Then I imported the same COM object into my actual solution, and the exact strings were implemented as a test, as in a test project.
When I run a real project, I get an InvalidCastException

Cannot pass a COM object of type "CTWebReport.WebReportCOMClass" to the interface type "CTWebReport.IWebReportCOM". This operation failed because a call to the QueryInterface COM component for the interface with IID '{5DFA18E8-4E71-4ADC-A812-6B166C242561} failed due to the following error: this interface is not supported (exception from HRESULT: 0x80004002 (E_NOINTERFACE)) .

I searched my entire system for every link to the interop and com library, including all the bin and obj folders that I could find. With the exception of the original COM library, I deleted them all and emptied the trash for good measure. No difference, exactly the same situation. The test project works, there is no real project.

EDIT
COM seems to work in winforms applications, but not in my librar class (which is consumed by the asp.net mvc web app).

I do not know what to do next. Suggestions?

+2
c # interop com
source share
2 answers

The difference was in streaming use. The winform thread executed code from the main thread, while asp.net did not. It was resolved by explicitly starting COM in STAThread.

+2
source share

Since your COM component runs in a WinForm application, but not in ASP.NET, I think you might run into some resolution problems. Can you temporarily increase the access rights to ASP.NET (for example, Administrator) and see if the component can be executed?

0
source share

All Articles