Check for empty path in TryLoadCustomDSM.

This commit is contained in:
Eugene Wang
2025-03-05 08:54:45 -05:00
parent 6b35b1735d
commit 5c15ec3711
2 changed files with 44 additions and 32 deletions

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!--change these in each release-->
<VersionPrefix>4.0.0.0</VersionPrefix>
<VersionSuffix>alpha.8</VersionSuffix>
<VersionSuffix>alpha.9</VersionSuffix>
<!--keep it the same until major # changes-->
<AssemblyVersion>4.0.0.0</AssemblyVersion>

View File

@@ -24,13 +24,25 @@ namespace NTwain.DSM
{
if (__dllPtr == IntPtr.Zero)
{
#if NETFRAMEWORK
var curFile = Assembly.GetExecutingAssembly().Location;
if (string.IsNullOrEmpty(curFile))
{
using var proc = Process.GetCurrentProcess();
curFile = proc.MainModule.FileName;
}
var folder = Path.GetDirectoryName(curFile);
#else
var folder = AppContext.BaseDirectory;
#endif
if (!string.IsNullOrEmpty(folder))
{
var dll = Path.Combine(
Path.GetDirectoryName(curFile)!,
folder,
$@"runtimes\win-{(TWPlatform.Is32bit ? "x86" : "x64")}\native\TWAINDSM.dll");
__dllPtr = LoadLibraryW(dll);
}
if (__dllPtr != IntPtr.Zero)
{