Skip to content

Commit

Permalink
Update NativeMethods.cs (#29)
Browse files Browse the repository at this point in the history
In Docker (ubuntu/Debian), when .net console app with PDFtoImage is call from another application, workingDirectory is not setup.

Assembly.GetExecutingAssembly().Location returns empty string, not null and new Uri(workingDirectory) than failes with exception "empty Uri"
  • Loading branch information
michalblaha authored Jul 30, 2023
1 parent ee12352 commit 65bfca9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/PDFtoImage/PdfiumViewer/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ static NativeMethods()
{
// Load the platform dependent Pdfium.dll if it exist.
#if NET7_0_OR_GREATER
var workingDirectory =
Assembly.GetExecutingAssembly().Location
?? Environment.ProcessPath!
?? AppContext.BaseDirectory;
string workingDirectory = Assembly.GetExecutingAssembly().Location;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = Environment.ProcessPath!;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = AppContext.BaseDirectory;
#elif NET6_0_OR_GREATER
var workingDirectory =
Assembly.GetExecutingAssembly().GetName(false).CodeBase
?? Environment.ProcessPath!
?? AppContext.BaseDirectory;
var workingDirectory = Assembly.GetExecutingAssembly().GetName(false).CodeBase;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = Environment.ProcessPath!;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = AppContext.BaseDirectory;
#else
var workingDirectory =
Assembly.GetExecutingAssembly().GetName(false).CodeBase
?? Process.GetCurrentProcess().MainModule!.FileName!
?? AppContext.BaseDirectory;
var workingDirectory =Assembly.GetExecutingAssembly().GetName(false).CodeBase;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = Process.GetCurrentProcess().MainModule!.FileName!;
if (string.IsNullOrWhiteSpace(workingDirectory))
workingDirectory = AppContext.BaseDirectory;
#endif

LoadNativeLibrary(Path.GetDirectoryName(new Uri(workingDirectory).LocalPath)!);
Expand Down

0 comments on commit 65bfca9

Please sign in to comment.