Dispose() public method

Call FreeLibrary on the unmanaged dll. All function pointers handed out from this class become invalid after this.
This is very dangerous because it suddenly invalidate everything retrieved from this dll. This includes any functions handed out via GetProcAddress, and potentially any objects returned from those functions (which may have an implemention in the dll).///
public Dispose ( ) : void
return void
Esempio n. 1
0
        static FdbNative()
        {
            var libraryPath = GetPreloadPath();

            if (libraryPath == null)
            {             // PInvoke will load
                return;
            }

            try
            {
                FdbCLib = UnmanagedLibrary.Load(libraryPath);
            }
            catch (Exception e)
            {
                if (FdbCLib != null)
                {
                    FdbCLib.Dispose();
                }
                FdbCLib = null;
                if (e is BadImageFormatException && IntPtr.Size == 4)
                {
                    e = new InvalidOperationException("The native FDB client is 64-bit only, and cannot be loaded in a 32-bit process.", e);
                }
                else
                {
                    e = new InvalidOperationException($"An error occurred while loading the native FoundationDB library: '{libraryPath}'.", e);
                }
                LibraryLoadError = ExceptionDispatchInfo.Capture(e);
            }
        }
Esempio n. 2
0
        static FdbNative()
        {
            // Impact of NativeLibPath:
            // - If null, don't preload the library, and let the CLR find the file using the default P/Invoke behavior
            // - If String.Empty, call win32 LoadLibrary("fdb_c.dll") and let the os find the file (using the standard OS behavior)
            // - Else, combine the path with "fdb_c.dll" and call LoadLibrary with the resulting (relative or absolute) path

            var libraryPath = Fdb.Options.NativeLibPath;

            if (libraryPath != null)
            {
                try
                {
                    if (libraryPath.Length == 0)
                    {                     // CLR will handle the search
                        libraryPath = FDB_C_DLL;
                    }
                    else if (!libraryPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                    {                     // add the file name
                        libraryPath = Path.Combine(Fdb.Options.NativeLibPath, FDB_C_DLL);
                    }

                    FdbCLib = UnmanagedLibrary.Load(libraryPath);
                }
                catch (Exception e)
                {
                    if (FdbCLib != null)
                    {
                        FdbCLib.Dispose();
                    }
                    FdbCLib = null;
                    if (e is BadImageFormatException && IntPtr.Size == 4)
                    {
                        e = new InvalidOperationException("The native FDB client is 64-bit only, and cannot be loaded in a 32-bit process.", e);
                    }
                    else
                    {
                        e = new InvalidOperationException("An error occurred while loading the native FoundationDB library", e);
                    }
                    LibraryLoadError = ExceptionDispatchInfo.Capture(e);
                }
            }
        }
		static FdbNative()
		{
			// Impact of NativeLibPath:
			// - If null, don't preload the library, and let the CLR find the file using the default P/Invoke behavior
			// - If String.Empty, call win32 LoadLibrary("fdb_c.dll") and let the os find the file (using the standard OS behavior)
			// - Else, combine the path with "fdb_c.dll" and call LoadLibrary with the resulting (relative or absolute) path

			var libraryPath = Fdb.Options.NativeLibPath;
			if (libraryPath != null)
			{
				try
				{
					if (libraryPath.Length == 0)
					{ // CLR will handle the search
						libraryPath = FDB_C_DLL;
					}
					else if (!libraryPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
					{ // add the file name
						libraryPath = Path.Combine(Fdb.Options.NativeLibPath, FDB_C_DLL);
					}

					FdbCLib = UnmanagedLibrary.Load(libraryPath);
				}
				catch (Exception e)
				{
					if (FdbCLib != null) FdbCLib.Dispose();
					FdbCLib = null;
					if (e is BadImageFormatException && IntPtr.Size == 4)
					{
						e = new InvalidOperationException("The native FDB client is 64-bit only, and cannot be loaded in a 32-bit process.", e);
					}
					else
					{
						e = new InvalidOperationException("An error occurred while loading the native FoundationDB library", e);
					}
					LibraryLoadError = ExceptionDispatchInfo.Capture(e);
				}
			}
		}