Custom AppDomainManager fails to start runtimeHost
Asked Answered
C

1

6

I have following appDomainManager code

public class HostAppDomainManager : AppDomainManager
{
    public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
    {
        this.InitializationFlags = AppDomainManagerInitializationOptions.RegisterWithHost;
    }
}

and following unmanaged code for starting the runtime host

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    ICLRMetaHost *pMetaHost       = NULL; 
    HRESULT hr;  
    ICLRRuntimeInfo *runtimeInfo = NULL;     
    __try 
    { 
        hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost); 
        hr = pMetaHost->GetRuntime(L"v4.0.30319",IID_ICLRRuntimeInfo,(LPVOID*)&runtimeInfo); 
        ICLRRuntimeHost *runtimeHost  = NULL; 
        hr = runtimeInfo->GetInterface(CLSID_CLRRuntimeHost,IID_ICLRRuntimeHost, (LPVOID*)&runtimeHost);     
        ICLRControl* clrControl = NULL; 
        hr = runtimeHost->GetCLRControl(&clrControl); 
        hr = clrControl->SetAppDomainManagerType(L"ExceptionThrower.dll",L"ExceptionThrower.HostAppDomainManager");
        hr = runtimeHost->Start();  
    } 
    __except(1) 
    { 
        wprintf(L"\n Error thrown %d",e); 
    } 
    return 0; 
} 

the call to runtimeHost->Start() fails with error code -2146233054, cansomeone point out what should i do to fix this ?

Cheryle answered 26/10, 2011 at 22:20 Comment(0)
C
6

if anyone else running into this, the problem is that the dll implementing AppDomainManager shoudl be strongly named.

so change the code to

hr = clrControl->SetAppDomainManagerType(L"ExceptionThrower, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3b6b01f2067f563",L"ExceptionThrower.HostAppDomainManager");
Cheryle answered 28/10, 2011 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.