【问题标题】:Custom AppDomainManager fails to start runtimeHost自定义 AppDomainManager 无法启动 runtimeHost
【发布时间】:2011-12-16 02:46:32
【问题描述】:

我有以下 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,有人能指出我应该如何解决这个问题吗?

【问题讨论】:

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


    【解决方案1】:

    如果其他人遇到这种情况,问题是实现 AppDomainManager 的 dll 应该被强命名。

    所以把代码改成

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

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      • 2017-09-08
      相关资源
      最近更新 更多