C++ program receiving HOST_E_CLRNOTAVAILABLE when calling a C# interface

0

I have a C++ program calling an interface I've implemented in C#. I'm consistently getting the error 0x80131023 HOST_E_CLRNOTAVAILABLE which is defined as CLR has been disabled due to unrecoverable error. The c++ program doesn't produce this error unless my program is being called but I can't see any of my functions in the stack trace. Does anyone have any tips on how go about identifying the problem?

EDIT: I'm using late binding to create an IDispatch interface.

 IUnknown* pUnknown;
 hRC = CoCreateInstance(
        MyProgID,                  
        0,                          
        CLSCTX_ALL,                 
        IID_IUnknown,               
        (void**) &pUnknown);        
hRC = pUnknown->QueryInterface(
        IID_IDispatch,              
        (void**) &_pService );      
pUnknown->Release();  

Then invoking with:

hRC = _pService->Invoke(
        _DispIDs[nDispIDIndex], IID_NULL, LOCALE_USER_DEFAULT,
        METHOD_TO_CALL, &Disp, &VarResult, NULL, NULL ); 

It calls most of the methods successfully with no error. When the Close method is called it returns the error mentioned.

c#
c++
com
asked on Stack Overflow Feb 3, 2012 by probably at the beach • edited Feb 3, 2012 by probably at the beach

1 Answer

1

The most likely failure mode here is that one of your calls tripped a managed exception that wasn't caught and caused the CLR to shut down. This might have happened in a thread that was started by the managed code so it won't get reported back to you with an HRESULT. That leaves a trace, the Output window ought to contain a notification for it, a "first chance exception" for exception type 0xe0534f4d.

Use a managed debugger to troubleshoot. VS has one: Project + Properties, Debugging, Debugger type setting. You can force a automatic break with Debug + Exceptions, tick the Thrown box for CLR exceptions.

answered on Stack Overflow Feb 3, 2012 by Hans Passant

User contributions licensed under CC BY-SA 3.0