Skip to content

Commit

Permalink
.NET: Add fallback for loading Microsoft.CSharp.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 1, 2024
1 parent 6756251 commit c525f06
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions csharp-api/REFrameworkNET/PluginLoadContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ public ref class PluginLoadContext : public System::Runtime::Loader::AssemblyLoa
// Relevant github issue: https://github.com/dotnet/runtime/issues/71629
if (assemblyName->Name == "Microsoft.CSharp")
{
System::Console::WriteLine("Searching in " + System::Runtime::InteropServices::RuntimeEnvironment::GetRuntimeDirectory() + " for Microsoft.CSharp.dll");
auto dir = System::Runtime::InteropServices::RuntimeEnvironment::GetRuntimeDirectory();
auto path = Microsoft::CSharp::RuntimeBinder::Binder::typeid->Assembly->Location;
auto dir = System::IO::Path::GetDirectoryName(path);

REFrameworkNET::API::LogInfo("Searching in " + dir + " for Microsoft.CSharp.dll");

if (auto assem = LoadFromAssemblyPath(System::IO::Path::Combine(dir, "Microsoft.CSharp.dll")); assem != nullptr) {
REFrameworkNET::API::LogInfo("Successfully loaded Microsoft.CSharp.dll from " + dir);
return assem;
}

REFrameworkNET::API::LogWarning("Falling back to loading Microsoft.CSharp.dll from runtime directory");

dir = System::Runtime::InteropServices::RuntimeEnvironment::GetRuntimeDirectory();
REFrameworkNET::API::LogInfo("Searching in " + dir + " for Microsoft.CSharp.dll");

if (auto assem = LoadFromAssemblyPath(System::IO::Path::Combine(dir, "Microsoft.CSharp.dll")); assem != nullptr) {
return assem;
}
Expand Down

0 comments on commit c525f06

Please sign in to comment.