From e562a7d72cb7b1bf00840a10c97af37c833a3735 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 31 Mar 2023 18:31:25 +0200 Subject: [PATCH] Fix loading C# assemblies from Mono AOT output --- Source/Engine/Scripting/ManagedCLR/MCore.cpp | 13 ++++++++++--- Source/Engine/Scripting/Runtime/DotNet.cpp | 10 ++++++++++ Source/Engine/Scripting/Runtime/Mono.cpp | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Scripting/ManagedCLR/MCore.cpp b/Source/Engine/Scripting/ManagedCLR/MCore.cpp index bc2f934d6..f56eb566c 100644 --- a/Source/Engine/Scripting/ManagedCLR/MCore.cpp +++ b/Source/Engine/Scripting/ManagedCLR/MCore.cpp @@ -65,16 +65,23 @@ bool MAssembly::Load(const String& assemblyPath, const StringView& nativePath) PROFILE_CPU(); ZoneText(*assemblyPath, assemblyPath.Length()); + const String* pathPtr = &assemblyPath; + String path; if (!FileSystem::FileExists(assemblyPath)) { - Log::FileNotFoundException ex(assemblyPath); - return true; + path = assemblyPath; + pathPtr = &path; + if (ResolveMissingFile(path)) + { + Log::FileNotFoundException ex(assemblyPath); + return true; + } } const auto startTime = DateTime::NowUTC(); OnLoading(); - if (LoadImage(assemblyPath, nativePath)) + if (LoadImage(*pathPtr, nativePath)) { OnLoadFailed(); return true; diff --git a/Source/Engine/Scripting/Runtime/DotNet.cpp b/Source/Engine/Scripting/Runtime/DotNet.cpp index f19fdf4d7..aab075306 100644 --- a/Source/Engine/Scripting/Runtime/DotNet.cpp +++ b/Source/Engine/Scripting/Runtime/DotNet.cpp @@ -761,6 +761,16 @@ MClass::MClass(const MAssembly* parentAssembly, void* handle, const char* name, classHandles.Add(handle, this); } +bool MAssembly::ResolveMissingFile(String& assemblyPath) const +{ +#if DOTNET_HOST_MONO + // Fallback to AOT-ed assembly location + assemblyPath = Globals::BinariesFolder / TEXT("Dotnet") / StringUtils::GetFileName(assemblyPath); + return !FileSystem::FileExists(assemblyPath); +#endif + return true; +} + MClass::~MClass() { _methods.ClearDelete(); diff --git a/Source/Engine/Scripting/Runtime/Mono.cpp b/Source/Engine/Scripting/Runtime/Mono.cpp index 363acdefb..3ebb92ccc 100644 --- a/Source/Engine/Scripting/Runtime/Mono.cpp +++ b/Source/Engine/Scripting/Runtime/Mono.cpp @@ -1170,6 +1170,11 @@ bool MAssembly::UnloadImage(bool isReloading) return false; } +bool MAssembly::ResolveMissingFile(String& assemblyPath) const +{ + return true; +} + MClass::MClass(const MAssembly* parentAssembly, MonoClass* monoClass, const StringAnsi& fullname) : _assembly(parentAssembly) , _fullname(fullname)