@@ -368,6 +368,20 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
368368 "" ,
369369 } ;
370370
371+ HashSet < string > basePaths = new ( ) ;
372+ void TryAddBasePath ( string path )
373+ {
374+ if ( path is not null )
375+ {
376+ try { basePaths . Add ( path ) ; }
377+ catch
378+ {
379+ /* Ignore */
380+ }
381+ }
382+ }
383+
384+
371385 // If the RocksDbNative package is referenced, then dynamically load it here so that it can tell us where the native libraries are
372386 string nativeCodeBase = null ;
373387 try
@@ -379,18 +393,24 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
379393 var getCodeBase = getCodeBaseMethod . CreateDelegate < Func < string > > ( ) ;
380394 nativeCodeBase = getCodeBase ( ) ;
381395 }
382- catch ( Exception )
396+ catch { /* Ignore */ }
397+
398+ //Some paths might throw NotSupportedException when used from single file deployment. We could test for that, but we can also just ignore it
399+ TryAddBasePath ( nativeCodeBase ) ;
400+ TryAddBasePath ( Directory . GetCurrentDirectory ( ) ) ;
401+ TryAddBasePath ( Path . GetDirectoryName ( UriToPath ( AppContext . BaseDirectory ) ) ) ;
402+ TryAddBasePath ( Path . GetDirectoryName ( UriToPath ( Transitional . CurrentFramework . GetBaseDirectory ( ) ) ) ) ;
403+ TryAddBasePath ( Path . GetDirectoryName ( UriToPath ( Assembly . GetEntryAssembly ( ) ? . Location ) ) ) ;
404+ TryAddBasePath ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) ? . Location ) ) ;
405+ TryAddBasePath ( Path . GetDirectoryName ( UriToPath ( typeof ( PosixImporter ) . GetTypeInfo ( ) . Assembly . Location ) ) ) ;
406+ TryAddBasePath ( Path . GetDirectoryName ( typeof ( PosixImporter ) . GetTypeInfo ( ) . Assembly . Location ) ) ;
407+
408+ // for Apple ARM64 - M1
409+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) && RuntimeInformation . ProcessArchitecture == Architecture . Arm64 )
383410 {
384- }
411+ TryAddBasePath ( "/opt/homebrew/lib" ) ;
412+ }
385413
386- var basePaths = new string [ ] {
387- nativeCodeBase ,
388- Path . GetDirectoryName ( UriToPath ( Transitional . CurrentFramework . GetBaseDirectory ( ) ) ) ,
389- Path . GetDirectoryName ( UriToPath ( Assembly . GetEntryAssembly ( ) ? . Location ) ) ,
390- Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) ? . Location ) ,
391- Path . GetDirectoryName ( UriToPath ( typeof ( PosixImporter ) . GetTypeInfo ( ) . Assembly . Location ) ) ,
392- Path . GetDirectoryName ( typeof ( PosixImporter ) . GetTypeInfo ( ) . Assembly . Location ) ,
393- } ;
394414 var search = basePaths
395415 . Where ( p => p != null )
396416 . Distinct ( )
0 commit comments