@@ -102,12 +102,37 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
102102 // libc/OpenSSL libraries. Try them out.
103103 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
104104 {
105- // The libraries are located at 'runtimes/<rid>/native/lib{libraryName}.so'
106- // The <rid> ends with the processor architecture. e.g. fedora-x64.
107105 string assemblyDirectory = Path . GetDirectoryName ( AppContext . BaseDirectory ) ;
108106 string processorArchitecture = RuntimeInformation . ProcessArchitecture . ToString ( ) . ToLowerInvariant ( ) ;
109107 string runtimesDirectory = Path . Combine ( assemblyDirectory , "runtimes" ) ;
110108
109+ // The default libgit2 binary is linked against OpenSSL 3. On hosts that have only
110+ // libcrypto.so.1.1 fall back to the OpenSSL-1.1 variant shipped alongside it. We probe
111+ // both layouts: flat (self-contained publish copies natives next to the assembly) and
112+ // 'runtimes/<rid>/native/' (framework-dependent / build output).
113+ if ( ! NativeLibrary . TryLoad ( "libcrypto.so.3" , out _ ) && NativeLibrary . TryLoad ( "libcrypto.so.1.1" , out _ ) )
114+ {
115+ string variantFile = $ "lib{ libraryName } -openssl1.1.so";
116+
117+ string flatVariantPath = Path . Combine ( assemblyDirectory , variantFile ) ;
118+ if ( NativeLibrary . TryLoad ( flatVariantPath , out handle ) )
119+ {
120+ return handle ;
121+ }
122+
123+ if ( Directory . Exists ( runtimesDirectory ) )
124+ {
125+ foreach ( var runtimeFolder in Directory . GetDirectories ( runtimesDirectory , $ "*-{ processorArchitecture } ") )
126+ {
127+ string variantPath = Path . Combine ( runtimeFolder , "native" , variantFile ) ;
128+ if ( NativeLibrary . TryLoad ( variantPath , out handle ) )
129+ {
130+ return handle ;
131+ }
132+ }
133+ }
134+ }
135+
111136 if ( Directory . Exists ( runtimesDirectory ) )
112137 {
113138 foreach ( var runtimeFolder in Directory . GetDirectories ( runtimesDirectory , $ "*-{ processorArchitecture } ") )
0 commit comments