Native Library Loader
Inheritance: IDisposable
Ejemplo 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);
            }
        }
Ejemplo 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);
				}
			}
		}