0

I meet a very strange situation, I made a solution (C# WPF), then one of the functions is to generate a PDF file, using pdfsharp library.

  • In debug or release All works fine
  • If I open the generated file (MySolution\bin\x64\Release\MySolution.exe), then the solution works all good, but nothing is happening when trying to generate pdf file(I mean not even a blank page as described here )

Opening that .exe file may not be exactly the same that launching solution in Release?

When I generate the pdf file, I create all by myself, adding lines and text, except one thing "new" for me : I generate a canvas, that I convert to .png, then place the .png in my .PDF. But don't see why it works differently if I launch from VS, or launch from explorer

Siegfried.V
  • 1,508
  • 1
  • 16
  • 34
  • I don't know if the external libraries are linked to the .exe file, that might be your problem. – Dimitri Bosteels Oct 29 '18 at 12:52
  • is there a way to check it? and when I launch in Release, release mode doesn't it excute that .exe file? – Siegfried.V Oct 29 '18 at 12:55
  • Maybe it does but with links etc. The best way to execute your app is to actually publish it (a function in visual studio) that allows you to run it independently from VS. – Dimitri Bosteels Oct 29 '18 at 13:00
  • 1
    are you working with absolute or relative paths? – owairc Oct 29 '18 at 13:20
  • Are you referencing images or other resources? When launched from VS, the working directory will be different and when run "standalone" it may not find the images it needs. Maybe add "try" and "catch" around the call to the PDF generator to see if the call causes exceptions (e.g. use MessageBox in the catch clause). – I liked the old Stack Overflow Oct 29 '18 at 13:28
  • ok, I could find the issue, I write as Answer as it is long to explain in comments, anyway thanks all for your help – Siegfried.V Oct 29 '18 at 13:36
  • just write quick answer here for you : I was saving the pdf in a restricted folder, as I launch VS "As administrator", it worked, but didn't work anymore as soon as I launched it from my user account – Siegfried.V Oct 29 '18 at 13:50

1 Answers1

0

well, the issue was really "trivial", but not obvious to me. To debug that I had no choice to add several Messagebox in all the code to identify it :

I was saving the pdf file in a folder in which I have no right to write files. As My VisualStudio was running "As Administrator", he could do that without any restriction. When I was launching my programm as normal user, he just couldn't write the file. I changed the folder to another one(Where all users can write in), but it was still not working. I then tried to open another pdf and it was not opening, I had 6 processes of Adobe Acrobat Reader in my Task Manager, but no pdf opening.

I just restarted computer, and now all is working fine.

I guess that trying to open a non existing file, Adobe just bugged?

Siegfried.V
  • 1,508
  • 1
  • 16
  • 34
  • So the error handling in your app did not exist before you tried running the application "standalone". – I liked the old Stack Overflow Oct 29 '18 at 14:15
  • yes, exactly, that's why I was surprised, in debug/release all was fine, untile I tried to launch it in standalone, just didn't think about privileges, in future I will have to remember about it cause where I launch my software there are lot of protections, I already met lot of problems "playing" with registers... – Siegfried.V Oct 29 '18 at 16:29
  • You should add error handling and logging to your apps as soon as you can otherwise you are going to get mad. Try having a look to the try/catch keywords and libraries like NLog for a start. – Juan Oct 30 '18 at 10:13
  • try/catch know it, NLog not, will follow your advises, thanks :) – Siegfried.V Oct 31 '18 at 09:15