NativeLibrary.TryLoad Method

Definition

Overloads

TryLoad(String, IntPtr)

Provides a simple API for loading a native library and returns a value that indicates whether the operation succeeded.

TryLoad(String, Assembly, Nullable<DllImportSearchPath>, IntPtr)

Provides a high-level API that loads a native library and returns a value that indicates whether the operation succeeded.

TryLoad(String, IntPtr)

Source:
NativeLibrary.cs
Source:
NativeLibrary.cs
Source:
NativeLibrary.cs

Provides a simple API for loading a native library and returns a value that indicates whether the operation succeeded.

public static bool TryLoad (string libraryPath, out IntPtr handle);

Parameters

libraryPath
String

The name of the native library to be loaded.

handle
IntPtr

When the method returns, the OS handle of the loaded native library.

Returns

true if the native library was loaded successfully; otherwise, false.

Exceptions

libraryPath is null.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9

TryLoad(String, Assembly, Nullable<DllImportSearchPath>, IntPtr)

Source:
NativeLibrary.cs
Source:
NativeLibrary.cs
Source:
NativeLibrary.cs

Provides a high-level API that loads a native library and returns a value that indicates whether the operation succeeded.

public static bool TryLoad (string libraryName, System.Reflection.Assembly assembly, System.Runtime.InteropServices.DllImportSearchPath? searchPath, out IntPtr handle);

Parameters

libraryName
String

The name of the native library to be loaded.

assembly
Assembly

The assembly loading the native library.

searchPath
Nullable<DllImportSearchPath>

The search path.

handle
IntPtr

When the method returns, the OS handle of the loaded native library.

Returns

true if the native library was loaded successfully; otherwise, false.

Exceptions

libraryPath or assembly is null.

assembly is not a RuntimeAssembly.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9