Skip to content

Commit

Permalink
fix: If GetCurrentAppDomainId fails try GetDefaultDomain first (.netf…
Browse files Browse the repository at this point in the history
…ramework remote start issue) (#178)

* fix: If GetCurrentAppDomainId fails try GetDefaultDomain first

a .net framework issue
---------

Co-authored-by: Aaron Robinson <[email protected]>
  • Loading branch information
mitchcapper and AaronRobinsonMSFT authored Nov 6, 2023
1 parent 4ea06f6 commit fdff3d4
Show file tree
Hide file tree
Showing 2 changed files with 22 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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dnne-analyzers", "src\dnne-analyzers\dnne-analyzers.csproj", "{2A4C07AB-EAA1-4B80-8A80-BD2DB6375C35}"
Expand Down
23 changes: 21 additions & 2 deletions src/platform/platform_v4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,32 @@ 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)
{
// This is a fallback attempt if the runtime is already activated
// and this thread isn't known to the runtime.
ICorRuntimeHost* oldRuntimeHost;
hr = runtimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void**)&oldRuntimeHost);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, hr, &_prepare_lock);
IUnknown* pUnk2;
hr = oldRuntimeHost->GetDefaultDomain(&pUnk2);
IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, hr, &_prepare_lock);

// Release resources.
(void)pUnk2->Release();
(void)oldRuntimeHost->Release();

hr = runtimeHost->GetCurrentAppDomainId(&_appDomainId);
}
(void)runtimeInfo->Release(); //can't release earlier incase backup failure

IF_FAILURE_RETURN_OR_ABORT(ret, failure_load_runtime, hr, &_prepare_lock);
(void)runtimeHost->QueryInterface(__uuidof(ICLRPrivRuntime), (void**)&_host);
(void)runtimeHost->Release();
assert(_host != nullptr);
Expand Down

0 comments on commit fdff3d4

Please sign in to comment.