3
3
#if NETCOREAPP3_1_OR_GREATER
4
4
5
5
using System . Reflection ;
6
+ using System . Runtime . InteropServices ;
6
7
using System . Runtime . Loader ;
7
8
using System . IO ;
8
9
using System ;
@@ -56,7 +57,7 @@ protected override Assembly Load(AssemblyName name)
56
57
if ( loadedAssembly != null )
57
58
{
58
59
log . Info ( "Assembly {0} ({1}) is loaded using the TestAssembliesResolver" , name , GetAssemblyLocationInfo ( loadedAssembly ) ) ;
59
-
60
+
60
61
return loadedAssembly ;
61
62
}
62
63
@@ -79,6 +80,45 @@ protected override Assembly Load(AssemblyName name)
79
80
return loadedAssembly ;
80
81
}
81
82
83
+ protected override IntPtr LoadUnmanagedDll ( string name )
84
+ {
85
+ log . Debug ( "Loading {0} unmanaged dll" , name ) ;
86
+
87
+ IntPtr loadedDllHandle = base . LoadUnmanagedDll ( name ) ;
88
+ if ( loadedDllHandle != IntPtr . Zero )
89
+ {
90
+ log . Info ( "Unmanaged DLL {0} is loaded using default base.LoadUnmanagedDll()" , name ) ;
91
+ return loadedDllHandle ;
92
+ }
93
+
94
+ string runtimeResolverPath = _runtimeResolver . ResolveUnmanagedDllToPath ( name ) ;
95
+ if ( string . IsNullOrEmpty ( runtimeResolverPath ) == false &&
96
+ File . Exists ( runtimeResolverPath ) )
97
+ {
98
+ loadedDllHandle = LoadUnmanagedDllFromPath ( runtimeResolverPath ) ;
99
+ }
100
+
101
+ if ( loadedDllHandle != IntPtr . Zero )
102
+ {
103
+ log . Info ( "Unmanaged DLL {0} ({1}) is loaded using the deps.json info" , name , runtimeResolverPath ) ;
104
+ return loadedDllHandle ;
105
+ }
106
+
107
+ string unmanagedDllPath = Path . Combine ( _basePath , name + ".dll" ) ;
108
+ if ( File . Exists ( unmanagedDllPath ) )
109
+ {
110
+ loadedDllHandle = LoadUnmanagedDllFromPath ( unmanagedDllPath ) ;
111
+ }
112
+
113
+ if ( loadedDllHandle != IntPtr . Zero )
114
+ {
115
+ log . Info ( "Unmanaged DLL {0} ({1}) is loaded using base path" , name , unmanagedDllPath ) ;
116
+ return loadedDllHandle ;
117
+ }
118
+
119
+ return IntPtr . Zero ;
120
+ }
121
+
82
122
private static string GetAssemblyLocationInfo ( Assembly assembly )
83
123
{
84
124
if ( assembly . IsDynamic )
0 commit comments