Improve custom dll import error handling
* Use NativeLibrary.Load instead of NativeLibrary.TryLoad * Add error details to the DllNotFoundException
This commit is contained in:
parent
0b6ff007c7
commit
d32feb765a
1 changed files with 16 additions and 6 deletions
|
|
@ -26,21 +26,31 @@ public static unsafe partial class Raylib
|
||||||
|
|
||||||
public static IntPtr ResolveDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
public static IntPtr ResolveDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||||
{
|
{
|
||||||
IntPtr handle = IntPtr.Zero;
|
string resolveNameError;
|
||||||
string libraryPath = GetLibraryPath(libraryName);
|
try
|
||||||
|
|
||||||
if (NativeLibrary.TryLoad(libraryName, assembly, searchPath, out handle))
|
|
||||||
{
|
{
|
||||||
|
IntPtr handle = NativeLibrary.Load(libraryName, assembly, searchPath);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
if (NativeLibrary.TryLoad(libraryPath, out handle))
|
|
||||||
{
|
{
|
||||||
|
resolveNameError = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
string resolvePathError;
|
||||||
|
string libraryPath = GetLibraryPath(libraryName);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IntPtr handle = NativeLibrary.Load(libraryPath);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
resolvePathError = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
throw new DllNotFoundException(
|
throw new DllNotFoundException(
|
||||||
$"Failed to load {libraryName}."
|
string.Join("\n", string.Empty, resolveNameError, resolvePathError)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue