InvalidCastException , Exception from HRESULT: 0x80004002 (E_NOINTERFACE)

hello..

 

I referenced a dll and use it in the main form, it works fine.

But when I create an object of other class, and try to use the method of the referenced dll in the object of other class, it throws me that exception...

anyone has any idea

Thanks in advance...

P/S  here's the whole message
Unable to cast COM object of type 'myDll.classInMyDll' to interface type 'myDll.IclassInMyDll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8859E613-39B9-435D-B0EC-0FD135388EE1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).




Answer this question

InvalidCastException , Exception from HRESULT: 0x80004002 (E_NOINTERFACE)

  • Renynet

    SOLVED!!!

    THANKS........

    my last prob:

    "well...tried that and things turned out that the thread goes into somekind of possible deaklock...with the err msg :"

    Solution:

    prev reply from JocularJoe:
    "

    Also you should not share the object between threads - each object should be called only on the thread that created it."



  • chamal

    > Do i have to do anything like that to my threads

    Yes. It looks like you are using COM Interop to call an STA (single-threaded apartment) COM DLL. The ApartmentState of the thread that calls the COM object must match the apartment state used by the COM DLL.

    Your main method is decorated with the STAThread attribute, so is an STA thread.

    You should make your worker thread STA by setting Thread.ApartmentState to ApartmentState.STA in code.

    Also you should not share the object between threads - each object should be called only on the thread that created it.


  • krompo

    I would hazard a guess that it may be related to Apartment Thread state
    There's really not alot of information to go on.

  • pradm

    I did mark the main class [STAThread]..

    Do i have to do anything like that to my threads

  • Vish - Ganini

    The DLL is this .NET DLL or some COM dll I'm not sure why you would be having any problems if it were a .NET Dll as assemblies have no problem. If it's a COM however then the Apartment state thread options that you chose or that were chosen when building it may effect this.

  • Regre

    well...tried that and things turned out that the thread goes into somekind of possible deaklock...with the err msg :

    -------------------------------------------------------------

    The CLR has been unable to transition from COM context 0x1a1170 to COM context 0x1a10b8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

    -------------------------------------------------------------

    But I believe setting Thread.ApartmentState to ApartmentState.STA should do the work...

    I think it is my own code that has a problem...still trying to slove it...
    maybe something related to the way I create another thread from a thread i created ..



  • bauts

    ok...here's what I found out..

    it throws me exception whenever i run the method in the Dll inside a thread I generate....

    the problem is how can I solve that
    I need to use the Dll in threads...

    Thanks...



  • InvalidCastException , Exception from HRESULT: 0x80004002 (E_NOINTERFACE)