@@ -24,8 +24,15 @@ CoreClr::CoreClr(alt::IServer* server) {
2424 strcat (defaultPath, windowsProgramFilesPath);
2525 GetPath (server, defaultPath);
2626 delete[] defaultPath;
27+
28+ const char *dotnetProgramFilesPath = " /dotnet/" ;
29+ dotnetDirectory = new char [strlen (dotnetProgramFilesPath) + strlen (pf) + 1 ];
30+ strcpy (dotnetDirectory, pf);
31+ strcat (dotnetDirectory, dotnetProgramFilesPath);
2732#else
2833 GetPath (server, " /usr/share/dotnet/host/fxr/" );
34+ dotnetDirectory = new char [strlen (" /usr/share/dotnet/" ) + 1 ];
35+ strcpy (dotnetDirectory, " /usr/share/dotnet/" );
2936#endif
3037#ifdef _WIN32
3138 const char *fileName = " /hostfxr.dll" ;
@@ -67,7 +74,8 @@ CoreClr::CoreClr(alt::IServer* server) {
6774}
6875
6976CoreClr::~CoreClr () {
70- free (runtimeDirectory);
77+ delete[] runtimeDirectory;
78+ delete[] dotnetDirectory;
7179}
7280
7381bool CoreClr::GetDelegate (alt::IServer* server, void * runtimeHost, unsigned int domainId, const char * moduleName,
@@ -374,8 +382,13 @@ void CoreClr::CreateManagedHost(alt::IServer* server) {
374382 auto wd = server->GetRootDirectory ().CStr ();
375383 auto hostCfgPath = alt::String (wd) + HostCfg;
376384 auto hostDllPath = alt::String (wd) + HostDll;
385+ auto hostExePath = alt::String (wd) + HostExe;
377386 server->LogInfo (alt::String (" coreclr-module: Prepare for loading config:" ) + hostCfgPath);
378- auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly ((const char_t *) hostCfgPath.CStr ());
387+ server->LogInfo (alt::String (" coreclr-module: dotnet root:" ) + dotnetDirectory);
388+ server->LogInfo (alt::String (" coreclr-module: host exe:" ) + hostExePath);
389+ auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly ((const char_t *) hostCfgPath.CStr (),
390+ (const char_t *) hostExePath.CStr (),
391+ (const char_t *) dotnetDirectory);
379392 if (load_assembly_and_get_function_pointer == nullptr ) return ;
380393 server->LogInfo (alt::String (" coreclr-module: Prepare for executing host:" ) + hostDllPath);
381394
@@ -423,11 +436,16 @@ void CoreClr::ExecuteManagedResource(alt::IServer* server, const char* resourceP
423436 ExecuteResourceDelegate (&args, sizeof (args));
424437}
425438
426- load_assembly_and_get_function_pointer_fn CoreClr::get_dotnet_load_assembly (const char_t * config_path) {
439+ load_assembly_and_get_function_pointer_fn
440+ CoreClr::get_dotnet_load_assembly (const char_t * config_path, const char_t * hostExe, const char_t * dotnetRoot) {
427441 // Load .NET Core
428442 void * load_assembly_and_get_function_pointer = nullptr ;
429443 hostfxr_handle cxt = nullptr ;
430- int rc = _initializeFxr (config_path, nullptr , &cxt);
444+ hostfxr_initialize_parameters initializeParameters{};
445+ initializeParameters.size = sizeof (hostfxr_initialize_parameters);
446+ initializeParameters.host_path = hostExe;
447+ initializeParameters.dotnet_root = dotnetRoot;
448+ int rc = _initializeFxr (config_path, &initializeParameters, &cxt);
431449 if (rc != 0 || cxt == nullptr ) {
432450 std::cerr << " Init failed: " << std::hex << std::showbase << rc << std::endl;
433451 _closeFxr (cxt);
0 commit comments