@@ -368,6 +368,20 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
368
368
"" ,
369
369
} ;
370
370
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
+
371
385
// If the RocksDbNative package is referenced, then dynamically load it here so that it can tell us where the native libraries are
372
386
string nativeCodeBase = null ;
373
387
try
@@ -379,18 +393,24 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
379
393
var getCodeBase = getCodeBaseMethod . CreateDelegate < Func < string > > ( ) ;
380
394
nativeCodeBase = getCodeBase ( ) ;
381
395
}
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 )
383
410
{
384
- }
411
+ TryAddBasePath ( "/opt/homebrew/lib" ) ;
412
+ }
385
413
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
- } ;
394
414
var search = basePaths
395
415
. Where ( p => p != null )
396
416
. Distinct ( )
0 commit comments