@@ -48,7 +48,7 @@ internal static unsafe class FdbNative
4848 private const string FDB_C_DLL = "libfdb_c.so" ;
4949#else
5050 /// <summary>Name of the C API dll used for P/Invoking</summary>
51- private const string FDB_C_DLL = "fdb_c.dll " ;
51+ private const string FDB_C_DLL = "fdb_c" ;
5252#endif
5353
5454 /// <summary>Handle on the native FDB C API library</summary>
@@ -236,40 +236,49 @@ static FdbNative()
236236 {
237237 // Impact of NativeLibPath:
238238 // - If null, don't preload the library, and let the CLR find the file using the default P/Invoke behavior
239- // - If String.Empty, call win32 LoadLibrary("fdb_c.dll") and let the os find the file (using the standard OS behavior)
240- // - Else, combine the path with "fdb_c.dll" and call LoadLibrary with the resulting (relative or absolute) path
239+ // - If String.Empty, call win32 LoadLibrary(FDB_C_DLL) and let the os find the file (using the standard OS behavior)
240+ // - If path is folder, append the FDB_C_DLL
241+ // Afterwards - call LoadLibrary with the resulting (relative or absolute) path
241242
242243 var libraryPath = Fdb . Options . NativeLibPath ;
243- if ( libraryPath != null )
244+
245+ if ( libraryPath == null )
246+ {
247+ return ;
248+ }
249+
250+ try
244251 {
245- try
252+ if ( libraryPath . Length == 0 )
253+ { // CLR will handle the search
254+ libraryPath = FDB_C_DLL ;
255+ }
256+ else
246257 {
247- if ( libraryPath . Length == 0 )
248- { // CLR will handle the search
249- libraryPath = FDB_C_DLL ;
250- }
251- else if ( ! libraryPath . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) )
252- { // add the file name
253- libraryPath = Path . Combine ( Fdb . Options . NativeLibPath , FDB_C_DLL ) ;
258+ var fileName = Path . GetFileName ( libraryPath ) ;
259+ if ( String . IsNullOrEmpty ( fileName ) )
260+ {
261+ libraryPath = Path . Combine ( libraryPath , FDB_C_DLL ) ;
254262 }
263+ }
255264
256- FdbCLib = UnmanagedLibrary . Load ( libraryPath ) ;
265+ FdbCLib = UnmanagedLibrary . Load ( libraryPath ) ;
266+ }
267+ catch ( Exception e )
268+ {
269+ if ( FdbCLib != null ) FdbCLib . Dispose ( ) ;
270+ FdbCLib = null ;
271+ if ( e is BadImageFormatException && IntPtr . Size == 4 )
272+ {
273+ e = new InvalidOperationException ( "The native FDB client is 64-bit only, and cannot be loaded in a 32-bit process." , e ) ;
257274 }
258- catch ( Exception e )
275+ else
259276 {
260- if ( FdbCLib != null ) FdbCLib . Dispose ( ) ;
261- FdbCLib = null ;
262- if ( e is BadImageFormatException && IntPtr . Size == 4 )
263- {
264- e = new InvalidOperationException ( "The native FDB client is 64-bit only, and cannot be loaded in a 32-bit process." , e ) ;
265- }
266- else
267- {
268- e = new InvalidOperationException ( "An error occurred while loading the native FoundationDB library" , e ) ;
269- }
270- LibraryLoadError = ExceptionDispatchInfo . Capture ( e ) ;
277+ e = new InvalidOperationException ( "An error occurred while loading the native FoundationDB library" , e ) ;
271278 }
279+ LibraryLoadError = ExceptionDispatchInfo . Capture ( e ) ;
272280 }
281+
273282 }
274283
275284 private static void EnsureLibraryIsLoaded ( )
0 commit comments