Always load hostfxr.dll by absolute path (#12807)
This commit is contained in:
parent
9459b73972
commit
8d68062cc4
|
|
@ -30,16 +30,17 @@ void HostFxrErrorRedirector::HostFxrErrorRedirectorCallback(const WCHAR* message
|
|||
m_writeFunction->Append(std::wstring(message) + L"\r\n");
|
||||
}
|
||||
|
||||
void HostFxr::Load()
|
||||
{
|
||||
HMODULE hModule;
|
||||
THROW_LAST_ERROR_IF(!GetModuleHandleEx(0, L"hostfxr.dll", &hModule));
|
||||
Load(hModule);
|
||||
}
|
||||
|
||||
void HostFxr::Load(HMODULE moduleHandle)
|
||||
{
|
||||
// A hostfxr may already be loaded here if we tried to start with an
|
||||
// invalid configuration. Release hostfxr before loading it again.
|
||||
if (m_hHostFxrDll != nullptr)
|
||||
{
|
||||
m_hHostFxrDll.release();
|
||||
}
|
||||
|
||||
m_hHostFxrDll = moduleHandle;
|
||||
|
||||
try
|
||||
{
|
||||
m_hostfxr_get_native_search_directories_fn = ModuleHelpers::GetKnownProcAddress<hostfxr_get_native_search_directories_fn>(moduleHandle, "hostfxr_get_native_search_directories");
|
||||
|
|
@ -63,9 +64,13 @@ void HostFxr::Load(HMODULE moduleHandle)
|
|||
|
||||
void HostFxr::Load(const std::wstring& location)
|
||||
{
|
||||
// Make sure to always load hostfxr via an absolute path.
|
||||
// If the process fails to start for whatever reason, a mismatched hostfxr
|
||||
// may be already loaded in the process.
|
||||
try
|
||||
{
|
||||
HMODULE hModule;
|
||||
LOG_INFOF(L"Loading hostfxr from location %s", location.c_str());
|
||||
THROW_LAST_ERROR_IF_NULL(hModule = LoadLibraryW(location.c_str()));
|
||||
Load(hModule);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
void Load();
|
||||
void Load(HMODULE moduleHandle);
|
||||
void Load(const std::wstring& location);
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ IN_PROCESS_APPLICATION::ExecuteApplication()
|
|||
|
||||
hostFxrResolutionResult->GetArguments(context->m_argc, context->m_argv);
|
||||
THROW_IF_FAILED(SetEnvironmentVariablesOnWorkerProcess());
|
||||
context->m_hostFxr.Load();
|
||||
context->m_hostFxr.Load(hostFxrResolutionResult->GetHostFxrLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue