sungaila / PDFtoImage

A .NET library to render PDF files into images.
https://www.sungaila.de/PDFtoImage/
MIT License
152 stars 15 forks source link

Loading of pdfium.dll fails when running in an IIS context #2

Closed JohannesEH closed 2 years ago

JohannesEH commented 2 years ago

Because IIS is shadow copying files you will get a path like C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\b7dc711f\a2c2b98f\assembly\dl3\8b76e845\0097b45e_1094d701\ when you call Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), and not the original path of the dll.

I'm not sure how to fix this in a way that works across all runtimes and environments. It would be nice if you could provide a pdfium.dll path yourself.

JohannesEH commented 2 years ago

Maybe something like Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) would work instead?

JohannesEH commented 2 years ago

Nah, CodeBase returns a Uri so it would be more like Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath)

The GetName has a boolean parameter specifying if the name should be the shadow copied (true) or original (false). It defaults to false. Then to unwrap the file uri