Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClickOnce Applications fail in certain circumstances #20

Open
jackmang opened this issue Aug 27, 2024 · 0 comments
Open

ClickOnce Applications fail in certain circumstances #20

jackmang opened this issue Aug 27, 2024 · 0 comments

Comments

@jackmang
Copy link

jackmang commented Aug 27, 2024

I spent hours trying to find a .Net 8 compatible way to print an existing PDF file that didn't require licensing. Something I thought was super simple, but isn't. This is where I ended up and I came here with low expectations. I am now very pleased that it works perfectly for my needs (Windows environment, .Net (Core)). Thank you for this.

I did run into an issue that required me to manually patch the code with a minor change. My application utilizes Microsoft ClickOnce for deployment, and in my case I am deploying framework Independent. It seems with ClickOnce, when you build framework independent, it puts your dependency files into the application folder (.\pdfium.dll) and not into a separate .\runtimes\win-x64\native\pdfium.dll folder as assumed in the code. This triggers the following exception:

throw new FileNotFoundException($"Native Library not found in path {path} or {Path.Combine(assemblySearchPath, fileName)}. " +
	$"Verify you have included the native Pdfium library in your application, " +
	$"or install the default libraries with the bblanchon.PDFium NuGet.");

I have a fix that seems to work for me. Unfortunately, I'm not a git user, so creating a pull request is a big ask, but I thought I'd share what worked for me without breaking the original code.

In PdfiumPrinter.LibraryLoader.NativeLibraryLoader.LoadNativeLibrary look for where it checks for !File.Exists(path). Replace that block with this...

if (!File.Exists(path))
{
	var libFound = Directory.EnumerateFiles(assemblySearchPath, fileName, SearchOption.TopDirectoryOnly).SingleOrDefault();
	if (!string.IsNullOrEmpty(libFound))
		path = libFound;
	else
		throw new FileNotFoundException($"Native Library not found in path {path} or {Path.Combine(assemblySearchPath, fileName)}. " +
			$"Verify you have included the native Pdfium library in your application, " +
			$"or install the default libraries with the bblanchon.PDFium NuGet.");
}

Alternatively, and I don't see this documented anywhere, it appears that maybe you could also call the static PdfiumPrinter.PdfLibrary.EnsureLoaded(pathToNativePDFiumDLL); to preset it explicitly to the location of your choice. This should work, but doesn't automatically adjust to different build types.

I hope this is helpful to someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant