@@ -78,18 +78,30 @@ private static class NativeMethods
7878 [ DllImport ( LIBDL ) ]
7979 public static extern SafeLibraryHandle dlopen ( string fileName , int flags ) ;
8080
81+
82+ [ DllImport ( LIBDL , SetLastError = true ) ]
83+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
84+ public static extern int dlclose ( IntPtr hModule ) ;
85+
8186#if __MonoCS__
8287
8388 public static SafeLibraryHandle LoadPlatformLibrary ( string fileName )
8489 {
8590 return dlopen ( fileName , 1 ) ;
8691 }
92+ public static bool FreePlatformLibrary ( IntPtr hModule ) { return dlclose ( hModule ) == 0 ; }
93+
8794#else
8895 const string KERNEL = "kernel32" ;
8996
9097 [ DllImport ( KERNEL , CharSet = CharSet . Auto , BestFitMapping = false , SetLastError = true ) ]
9198 public static extern SafeLibraryHandle LoadLibrary ( string fileName ) ;
9299
100+ [ ReliabilityContract ( Consistency . WillNotCorruptState , Cer . Success ) ]
101+ [ DllImport ( KERNEL , SetLastError = true ) ]
102+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
103+ public static extern bool FreeLibrary ( IntPtr hModule ) ;
104+
93105 public static SafeLibraryHandle LoadPlatformLibrary ( string fileName )
94106 {
95107 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
@@ -98,6 +110,15 @@ public static SafeLibraryHandle LoadPlatformLibrary(string fileName)
98110 }
99111 return dlopen ( fileName , 1 ) ;
100112 }
113+
114+ public static bool FreePlatformLibrary ( IntPtr hModule )
115+ {
116+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
117+ {
118+ return FreeLibrary ( hModule ) ;
119+ }
120+ return return dlclose ( hModule ) == 0 ;
121+ }
101122#endif
102123 }
103124
0 commit comments