Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load unmanaged assemblies the same way as managed assemblies. #1370

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down