I'm using PdfSharp to generate a pdf based on images. The problem is that after doing this, I'm not able to delete the files and I get the following exception:
{"The process cannot access the file because it is being used by another process."}
I've found that what's causing this is when I'm using the XImage.FromFile function to access the image ahead of drawing it on the pdf. Using XImage.Dispose() is not enough either.
What should I do to be able to delete a file after using XImage.FromFile?
Use PDFsharp 1.50 beta, use the GDI+ build, or modify your current PDFsharp version (you have to open the file with CacheOption = BitmapCacheOption.OnLoad
).
More information:
https://stackoverflow.com/a/6430416/162529
http://forum.pdfsharp.net/viewtopic.php?p=5654#p5654