diff --git a/DNNE.sln b/DNNE.sln index ecd656b..90b74e5 100644 --- a/DNNE.sln +++ b/DNNE.sln @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "platform", "platform", "{95 ProjectSection(SolutionItems) = preProject src\platform\dnne.h = src\platform\dnne.h src\platform\platform.c = src\platform\platform.c + src\platform\platform_v4.cpp = src\platform\platform_v4.cpp EndProjectSection EndProject Global diff --git a/src/platform/dnne.h b/src/platform/dnne.h index 6b4b6f1..68a842a 100644 --- a/src/platform/dnne.h +++ b/src/platform/dnne.h @@ -75,6 +75,8 @@ enum failure_type { failure_load_runtime = 1, failure_load_export, + failure_get_current_app_domain_id, + failure_get_current_app_domain_id_backup_try }; typedef void (DNNE_CALLTYPE* failure_fn)(enum failure_type type, int error_code); diff --git a/src/platform/platform_v4.cpp b/src/platform/platform_v4.cpp index c3b85ef..8ac94e3 100644 --- a/src/platform/platform_v4.cpp +++ b/src/platform/platform_v4.cpp @@ -155,13 +155,26 @@ namespace // Release all other CLR resources (void)metahost->Release(); - (void)runtimeInfo->Release(); + // Start the runtime hr = runtimeHost->Start(); IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, hr, &_prepare_lock); - (void)runtimeHost->GetCurrentAppDomainId(&_appDomainId); + hr = runtimeHost->GetCurrentAppDomainId(&_appDomainId); + if (hr != S_OK) + { + ICorRuntimeHost* oldRuntimeHost; + hr = runtimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void**)&oldRuntimeHost); + IF_FAILURE_RETURN_OR_ABORT(ret, failure_get_current_app_domain_id_backup_try, hr, &_prepare_lock); + IUnknown* pUnk2; + hr = oldRuntimeHost->GetDefaultDomain(&pUnk2); + IF_FAILURE_RETURN_OR_ABORT(ret, failure_get_current_app_domain_id_backup_try, hr, &_prepare_lock); + hr = runtimeHost->GetCurrentAppDomainId(&_appDomainId); + } + (void)runtimeInfo->Release();//can't release earlierincase backup failure + + IF_FAILURE_RETURN_OR_ABORT(ret, failure_get_current_app_domain_id, hr, &_prepare_lock); (void)runtimeHost->QueryInterface(__uuidof(ICLRPrivRuntime), (void**)&_host); (void)runtimeHost->Release(); assert(_host != nullptr);