diff --git a/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs b/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs index cf9ed03f9..800de29da 100644 --- a/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs +++ b/src/NUnitEngine/nunit.engine.core/Internal/TestAssemblyLoadContext.cs @@ -3,6 +3,7 @@ #if NETCOREAPP3_1_OR_GREATER using System.Reflection; +using System.Runtime.InteropServices; using System.Runtime.Loader; using System.IO; using System; @@ -56,7 +57,7 @@ protected override Assembly Load(AssemblyName name) if (loadedAssembly != null) { log.Info("Assembly {0} ({1}) is loaded using the TestAssembliesResolver", name, GetAssemblyLocationInfo(loadedAssembly)); - + return loadedAssembly; } @@ -79,6 +80,45 @@ protected override Assembly Load(AssemblyName name) return loadedAssembly; } + protected override IntPtr LoadUnmanagedDll(string name) + { + log.Debug("Loading {0} unmanaged dll", name); + + IntPtr loadedDllHandle = base.LoadUnmanagedDll(name); + if (loadedDllHandle != IntPtr.Zero) + { + log.Info("Unmanaged DLL {0} is loaded using default base.LoadUnmanagedDll()", name); + return loadedDllHandle; + } + + string runtimeResolverPath = _runtimeResolver.ResolveUnmanagedDllToPath(name); + if (string.IsNullOrEmpty(runtimeResolverPath) == false && + File.Exists(runtimeResolverPath)) + { + loadedDllHandle = LoadUnmanagedDllFromPath(runtimeResolverPath); + } + + if (loadedDllHandle != IntPtr.Zero) + { + log.Info("Unmanaged DLL {0} ({1}) is loaded using the deps.json info", name, runtimeResolverPath); + return loadedDllHandle; + } + + string unmanagedDllPath = Path.Combine(_basePath, name + ".dll"); + if (File.Exists(unmanagedDllPath)) + { + loadedDllHandle = LoadUnmanagedDllFromPath(unmanagedDllPath); + } + + if (loadedDllHandle != IntPtr.Zero) + { + log.Info("Unmanaged DLL {0} ({1}) is loaded using base path", name, unmanagedDllPath); + return loadedDllHandle; + } + + return IntPtr.Zero; + } + private static string GetAssemblyLocationInfo(Assembly assembly) { if (assembly.IsDynamic)