Fixed the wrong version of .NET Runtime being loaded

This commit is contained in:
Kah Wei 2023-10-29 17:03:44 +08:00
parent f279f1f54c
commit 76847a4d9c
1 changed files with 18 additions and 11 deletions

View File

@ -76,15 +76,14 @@ namespace SHADE
if (coreClr == nullptr) if (coreClr == nullptr)
{ {
// Construct the CoreCLR path // Construct the CoreCLR path
std::string coreClrPath("C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\5.0.17"); // Works const std::string CORE_CLR_PATH = DOT_NET_PATH->string() + "\\coreclr.dll";
coreClrPath += "\\coreclr.dll";
// Load the CoreCLR DLL // Load the CoreCLR DLL
coreClr = LoadLibraryExA(coreClrPath.c_str(), nullptr, 0); coreClr = LoadLibraryExA(CORE_CLR_PATH.c_str(), nullptr, 0);
if (!coreClr) if (!coreClr)
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "[DotNetRuntime] Error #" << GetLastError() << " Failed to load CoreCLR from \"" << coreClrPath << "\"\n"; oss << "[DotNetRuntime] Error #" << GetLastError() << " Failed to load CoreCLR from \"" << CORE_CLR_PATH << "\"\n";
throw std::runtime_error(oss.str()); throw std::runtime_error(oss.str());
} }
@ -100,7 +99,7 @@ namespace SHADE
// trusted system assemblies (similar to the .NET Framework GAC). // trusted system assemblies (similar to the .NET Framework GAC).
// For this host (as with most), assemblies next to CoreCLR will // For this host (as with most), assemblies next to CoreCLR will
// be included in the TPA list // be included in the TPA list
std::string tpaList = buildTpaList(DOT_NET_PATH->string()); std::string tpaList = buildTpaList(DOT_NET_PATH->string()) + buildTpaList(runtimePath);
// Define CoreCLR properties // Define CoreCLR properties
std::array propertyKeys = std::array propertyKeys =
@ -159,7 +158,7 @@ namespace SHADE
std::string SHDotNetRuntime::buildTpaList(const std::string& directory) std::string SHDotNetRuntime::buildTpaList(const std::string& directory)
{ {
// Constants // Constants
static const std::string SEARCH_PATH = directory + "\\*.dll"; const std::string SEARCH_PATH = directory + "\\*.dll";
static constexpr char PATH_DELIMITER = ';'; static constexpr char PATH_DELIMITER = ';';
// Create a osstream object to compile the string // Create a osstream object to compile the string
@ -249,12 +248,20 @@ namespace SHADE
const auto thisMinor = stoi(VERSION_TOKENS[1]); const auto thisMinor = stoi(VERSION_TOKENS[1]);
const auto thisRevision = stoi(VERSION_TOKENS[2]); const auto thisRevision = stoi(VERSION_TOKENS[2]);
if (major > thisRevision) // Only pass if the version is greater
continue; if (major > thisMajor)
if (minor > thisMinor)
continue;
if (revision > thisRevision)
continue; continue;
else if (major == thisMajor)
{
if (minor > thisMinor)
continue;
else if (minor == thisMinor)
{
if (revision > thisRevision)
continue;
}
}
major = thisMajor; major = thisMajor;
minor = thisMinor; minor = thisMinor;