cp79shark / Shark.PdfConvert

Simple .NET Core wrapper for WkHTMLToPDF tool.
MIT License
33 stars 13 forks source link

IOException in the library #10

Closed Zulukas closed 4 years ago

Zulukas commented 5 years ago

It doesn't seem like this library is getting much attention anymore, but I figure I'll put this here just in case the developer sees it. It appears the library is throwing an IOException when attempting to delete one of the temporary files it creates in C:\WINDOWS\TEMP. Here is the error I got:

The process cannot access the file 'C:\WINDOWS\TEMP\ce20a607-f3c8-4116-bd58-74a731b790b0.html' because it is being used by another process. STACKTRACE: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at Shark.PdfConvert.PdfConvert.Convert(PdfConversionSettings config, Stream pdfOutputStream, Stream contentInputStream, Stream coverInputStream, Stream footerInputStream, Stream headerInputStream, Action`2 outputCallback) at .ConvertToPdf(String& htmlText) in :line 67

I know for a fact I'm not doing anything in the temp directory in my application, and when I dug down into this library I saw that you're creating and writing the html content into a temporary file in the format of ".html" out at C:\Windows\Temp.

I looked through the code to see where the file is getting used, and I'm unable to tell exactly which file it is that is having the issue when being deleted. I'm using this library in a small print service that my server uses, it seems like the issue is happening early in the morning. My sneaking suspicion is that Windows is locking down this file somehow because of where it lives, but I don't know enough about Windows to make that kind of conclusion. I'll be running a test on my end here to see if I can replicate the issue after not printing something for a while and coming back in in the morning and trying again and see if the issue repeats. If that's the case, I'll likely just fork off the project and modify the code to cause the temporary files to be created in a folder I know the system won't fiddle with and see then if the issue persists. As far as I can tell, the library is properly handling files, and it's not an immediate logic problem.

N30NF15H commented 5 years ago

Any chance you have indexing turned on for the server?

You should be able to modify the temp folder path using the pdfConversionSettings.TempFilesPath without needing to fork.

cp79shark commented 4 years ago

Need to be better about getting on here, sorry for the delay. I am going to assume you've modified the property as suggested and are working fine?