PDFtoPrinter
PDFtoPrinter copied to clipboard
File not found when printing from web service
I am trying to print from a .NET web service. The exception being thrown is "The system cannot find the file specified". I assume that means the pdf itself, but the file does exist. System.IO.File.Exists(mypdffile) run during debug returns true. The service is running in Visual Studio 2013 framework 4.7 on my local box on which I am an admin. If I use the same code in a console app it works fine. The PDFtoPrinter.dll and PDFtoPrinter.exe are in the project's bin folder.
var wrapper = new PDFtoPrinterPrinter();
await wrapper
.Print(new PrintingOptions(
printer, filePath)
);
Update: I noticed a closed post where someone was having the same issue but in a WPF project. A recommendation was to install using Nuget rather than manually (even though that works in a console app). Unfortunately, the install fails and is rolled back:
Thanks for any help.
Hi @JeffSE97062
Could you please provide your ".csproj" file? This will help to investigate the issue.
EmailService.zip Hi @svishnevsky, file is attached.
Hi @JeffSE97062 Could you please try version 1.3.1 of the package and let me know if it works? (https://www.nuget.org/packages/PDFtoPrinter/1.3.2)
As I see the issue is in https://github.com/svishnevsky/PDFtoPrinter/blob/master/PDFtoPrinter/build/PDFtoPrinter.targets
However it is required for other projects. I still trying different conditions to do not break existing platforms support. Will keep you updated if I'll find an options to support all cases.
Hi @svishnevsky, your last message said to try 1.3.1 but your link is to 1.3.2. Can you please clarify?
Hi @JeffSE97062 Sorry for confusion. Please try 1.3.1 https://www.nuget.org/packages/PDFtoPrinter/1.3.1
@svishnevsky 1.3.1 installed without errors, but the project wouldn't build because it couldn't find the file "...packages\PDFtoPrinter.1.3.1\buildPDF-XChange Viewer Settings.dat". I copied the file (not sure if version matters??) into the expected folder and the project built successfully, but I received the same error: "The system cannot find the file specified".
I believe that the file not found is PDFtoPrinter.exe on Process Start. I am getting this error, even with PDFtoPrinter.exe and .dll (as well as PDF-X-Change Viewer Settings.dat) in the bin folder.
That file is in my bin as well as the dll. Identical setup in a console app works, just not in a web service. Seems to work in a Windows service as well.
@JeffSE97062 sorry for the long response, it is not easy to reproduce this issue. What approach do you use to build a windows service? I use in person Topshelf and it works fine.
@svishnevsky I am actually getting the file-not-found error in a .NET web (not Windows) service. I am using VS 2013 .NET 4.5 with the 1.3.1 Nuget package installed. Solution compiles OK.