自定义AppDomainManager无法启动runtimeHost

时间:2011-10-26 22:20:56

标签: c# .net-4.0 clr-hosting

我有以下appDomainManager代码

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

并遵循用于启动运行时主机的非托管代码

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; 
} 

对runtimeHost-> Start()的调用失败,错误代码为-2146233054,cansomeone指出我应该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:6)

如果有其他人遇到此问题,问题是实现AppDomainManager的dll强烈命名。

所以将代码更改为

hr = clrControl->SetAppDomainManagerType(L"ExceptionThrower, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3b6b01f2067f563",L"ExceptionThrower.HostAppDomainManager");