22using System . Collections . Generic ;
33using System . IO ;
44using System . Reflection ;
5+ using System . Runtime . InteropServices ;
56using LibGit2Sharp . Core ;
67
78namespace LibGit2Sharp
@@ -13,6 +14,7 @@ public static class GlobalSettings
1314 {
1415 private static readonly Lazy < Version > version = new Lazy < Version > ( Version . Build ) ;
1516 private static readonly Dictionary < Filter , FilterRegistration > registeredFilters ;
17+ private static readonly bool nativeLibraryPathAllowed ;
1618
1719 private static LogConfiguration logConfiguration = LogConfiguration . None ;
1820
@@ -21,7 +23,9 @@ public static class GlobalSettings
2123
2224 static GlobalSettings ( )
2325 {
24- if ( Platform . OperatingSystem == OperatingSystemType . Windows )
26+ nativeLibraryPathAllowed = Platform . IsRunningOnNetFramework ( ) ;
27+
28+ if ( nativeLibraryPathAllowed )
2529 {
2630 /* Assembly.CodeBase is not actually a correctly formatted
2731 * URI. It's merely prefixed with `file:///` and has its
@@ -148,23 +152,24 @@ public static LogConfiguration LogConfiguration
148152 }
149153
150154 /// <summary>
151- /// Sets a hint path for searching for native binaries: when
152- /// specified, native binaries will first be searched in a
153- /// subdirectory of the given path corresponding to the operating
154- /// system and architecture (eg, "x86" or "x64") before falling
155- /// back to the default path ("lib\win32\x86" or "lib\win32\x64"
156- /// next to the application).
155+ /// Sets a path for loading native binaries on .NET Framework.
156+ /// When specified, native .dll will first be searched in a
157+ /// subdirectory of the given path corresponding to the
158+ /// architecture ("x86" or "x64") before falling
159+ /// back to searching the default load directories
160+ /// (<see cref="DllImportSearchPath.AssemblyDirectory"/>,
161+ /// <see cref="DllImportSearchPath.ApplicationDirectory"/> and
162+ /// <see cref="DllImportSearchPath.SafeDirectories"/>).
157163 /// <para>
158164 /// This must be set before any other calls to the library,
159- /// and is not available on Unix platforms: see your dynamic
160- /// library loader's documentation for details.
165+ /// and is not available on other platforms than .NET Framework.
161166 /// </para>
162167 /// </summary>
163168 public static string NativeLibraryPath
164169 {
165170 get
166171 {
167- if ( Platform . OperatingSystem != OperatingSystemType . Windows )
172+ if ( ! nativeLibraryPathAllowed )
168173 {
169174 throw new LibGit2SharpException ( "Querying the native hint path is only supported on Windows platforms" ) ;
170175 }
@@ -174,7 +179,7 @@ public static string NativeLibraryPath
174179
175180 set
176181 {
177- if ( Platform . OperatingSystem != OperatingSystemType . Windows )
182+ if ( ! nativeLibraryPathAllowed )
178183 {
179184 throw new LibGit2SharpException ( "Setting the native hint path is only supported on Windows platforms" ) ;
180185 }
@@ -184,14 +189,21 @@ public static string NativeLibraryPath
184189 throw new LibGit2SharpException ( "You cannot set the native library path after it has been loaded" ) ;
185190 }
186191
187- nativeLibraryPath = value ;
192+ try
193+ {
194+ nativeLibraryPath = Path . GetFullPath ( value ) ;
195+ }
196+ catch ( Exception e )
197+ {
198+ throw new LibGit2SharpException ( e . Message ) ;
199+ }
188200 }
189201 }
190202
191203 internal static string GetAndLockNativeLibraryPath ( )
192204 {
193205 nativeLibraryPathLocked = true ;
194- return nativeLibraryPath ;
206+ return Path . Combine ( nativeLibraryPath , Platform . ProcessorArchitecture ) ;
195207 }
196208
197209 /// <summary>
0 commit comments