@@ -127,13 +127,13 @@ internal static bool TryLoad(string fileName, string hintPath)
127127 }
128128
129129 // If we have hint path provided by the user, look there first
130- if ( TryLoadFromDirectory ( fileName , hintPath ) )
130+ if ( hintPath != null && TryLoadFromDirectory ( fileName , hintPath ) )
131131 {
132132 return true ;
133133 }
134134
135135 // If we have an overall hint path provided by the user, look there next
136- if ( Control . NativeProviderPath != hintPath && TryLoadFromDirectory ( fileName , Control . NativeProviderPath ) )
136+ if ( Control . NativeProviderPath != null && Control . NativeProviderPath != hintPath && TryLoadFromDirectory ( fileName , Control . NativeProviderPath ) )
137137 {
138138 return true ;
139139 }
@@ -252,6 +252,9 @@ static bool TryLoadFile(string directory, string relativePath, string fileName)
252252 return false ;
253253 }
254254
255+ #if NET5_0_OR_GREATER
256+ return NativeLibrary . TryLoad ( fullPath , out libraryHandle ) ;
257+ #else
255258 // If successful this will return a handle to the library
256259 libraryHandle = IsUnix ? UnixLoader . LoadLibrary ( fullPath ) : WindowsLoader . LoadLibrary ( fullPath ) ;
257260 if ( libraryHandle == IntPtr . Zero )
@@ -267,9 +270,11 @@ static bool TryLoadFile(string directory, string relativePath, string fileName)
267270 }
268271
269272 return libraryHandle != IntPtr . Zero ;
273+ #endif
270274 }
271275 }
272276
277+ #if ! NET5_0_OR_GREATER
273278 [ SuppressUnmanagedCodeSecurity ]
274279 [ SecurityCritical ]
275280 static class WindowsLoader
@@ -297,8 +302,9 @@ public static IntPtr LoadLibrary(string fileName)
297302
298303 const int RTLD_NOW = 2 ;
299304
300- [ DllImport ( "libdl.so " , SetLastError = true ) ]
305+ [ DllImport ( "libdl" , SetLastError = true ) ]
301306 static extern IntPtr dlopen ( String fileName , int flags ) ;
302307 }
308+ #endif
303309 }
304310}
0 commit comments