Skip to content

Commit

Permalink
fix: If GetCurrentAppDomainId fails try GetDefaultDomain first
Browse files Browse the repository at this point in the history
a .net framework issue
  • Loading branch information
mitchcapper committed Aug 31, 2023
1 parent 0093cdc commit de5beac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions DNNE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/platform/dnne.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 15 additions & 2 deletions src/platform/platform_v4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit de5beac

Please sign in to comment.