Tuesday, October 4, 2011

‘The file exists’ and Path.GetTempFileName Exception


I was working with Acapela (Text to Speech) ActiveX control. My webservice is using this control to synthesize speech. The problem on production suddenly came with an error message.

System.IO.IOException: The file exists. 
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.Path.GetTempFileName()

I was thinking about the issue why temp file is not created and it wrongly says ‘The file exists’.
In actual machine’s Temp folder (c:\windows\temp) contains a large number of temp files. The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.  Each voice generation call by web service generates two temp files without deleting them. So there is no temp file sweep policy defined and this problem occurred when quota exceeded.
The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unnecessary temporary files.

Luckily it was not end user product, otherwise we have to provide the fixes to clients. I just fixed it on production server.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I recomend not using Path.GetTempFileName() at all. More details in my blog http://morten.bravonet.no/path-gettempfilename-causes-the-file-exists-exception

    ReplyDelete