I have an odd, intermittent bug that is happening on a web server.
One of the methods triggers the creation of a small file (3kb), in a folder. The folder is based on the current year, month and location id.
The file is created by a 3rd party component that I have no control over, other than by calling its
The developers of this component have confirmed that they hand the creation of the file over to the OS and then return without checking if the creation happened. (Nice).
What we then try to do is to open this file, and write a specific authorisation code on it. However, occasionally the log files are catching a
System.ArgumentException: Parameter is not valid when I call
Bitmap bmpImage = new Bitmap(filename); According to MSDN this exception means that the file is not an image file, or is not actually there.
I can't affect the 3rd party component, But I am pretty sure that Running a
FileSystemWatcher on a website process is not going to cut it either, nor is any kind of blocking call where I wait for an unknown amount of time for the file to be created. The only other solution I can think of off the top of my head is to check if the file is there, if not, check after a second, and then a third time. If after all that it is not present, to throw an exception. But that just feels more like a 'bodge' than a fix.
I can't put these image creations and alterations into some kind of queue or other process, as the updated image is displayed back to the user on the next page.
Have I missed any obvious solutions to my problem here, before I need to go back and try to re-invent the whole process (Which seems overkill for maybe 1 in 500) images causing a problem?