3

I have a native process which uses .NET component via COM interop. Once the process is up, I am trying to get interface pointers to the various CLR managers such as ICLRDebugManager, ICLRGCManager, etc. using the ICLRControl interface pointer. I'm able to reach up to acquiring ICLRControl interface without a glitch. ICLRRuntimeInfo also correctly tells me that it is 4.0.x .net version when I call GetVersionString on it.

It is only that the ICLRControl::GetCLRManager keeps failing with error 0x80130122, which error code stands for HOST_E_INVALIDOPERATION. Searched the internet, but could not get information as to why this might be failing. Any help is much appreciated.

TIA.

WinCPP

Edit 1. Adding code snippet.

    // ICLRRuntimeInfo interface pointer
    CComQIPtr<ICLRRuntimeInfo> pCLRRuntimeInfo = pUnk;
    if (!pCLRRuntimeInfo)
    {
        cout << "failed to get run time info interface pointer" << endl;
        return;
    }

    TCHAR version[128];
    memset(version, 0, 128);
    DWORD count = 127;
    pCLRRuntimeInfo->GetVersionString(version, &count);
    cout << version << endl;

    // ICLRRuntimeHost
    CComPtr<ICLRRuntimeHost> pCLRRuntimeHost = 0;
    hr = pCLRRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&pCLRRuntimeHost);
    if (FAILED(hr))
    {
        cout << "failed to get run time host interface pointer" << endl;
        return;
    }

    // ICLRControl
    CComPtr<ICLRControl> pCLRControl = 0;
    hr = pCLRRuntimeHost->GetCLRControl(&pCLRControl);
    if (FAILED(hr))
    {
        cout << "failed to get clr control interface pointer" << endl;
        return;
    }

    ///////////////////////////////////////////
    // Everything is successful upto this point
    ///////////////////////////////////////////

    // ICLRGCManager
    CComPtr<ICLRGCManager> pCLRGCManager = 0;
    hr = pCLRControl->GetCLRManager(IID_ICLRGCManager, (LPVOID *)&pCLRGCManager);
    if (FAILED(hr))
    {
        cout << "failed to get GC manager interface pointer" << endl;
        return;
    }

    // Above call fails with the error 0x81031022, though everything is as per the MSDN documentation for the API
WinCPP
  • 75
  • 2
  • 8
  • Don't make us guess what IID you are asking for and exactly when you do so. Post your code. – Hans Passant Oct 10 '13 at 15:18
  • 1
    @HansPassant I have updated the question with the code snippet. Surprisingly, the above code works fine in my test app in which I create a CLR instance explicitly. My intention is to latch on to already loaded CLR instance in the native process, when the last call i.e. GetCLRManager fails. Thanks! – WinCPP Oct 11 '13 at 06:46

1 Answers1

1

Looking at this source code on GitHub, it looks like CCorCLRControl::GetCLRManager will return HOST_E_INVALIDOPERATION if the runtime has already been started.

This explains why you are receiving that error code when attempting to "latch on to already loaded CLR instance," but that you meet with success when you create a CLR instance explicitly.

kkahl
  • 415
  • 5
  • 17