Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom AppDomainManager fails to start runtimeHost

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 ?

like image 624
np-hard Avatar asked Oct 26 '11 22:10

np-hard


1 Answers

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");
like image 164
np-hard Avatar answered Sep 29 '22 12:09

np-hard