Tuesday, October 25, 2011

System.IO.IOException: The file exists

Yesterday when we where starting up for the morning we discovered that one of our test sites was returning the ever so friendly Yellow Screen of Death with an even friendlier message: "The file exists", Really!
A closer look to the stack trace reviled little more information.


The line reads:
System.IO.Path.GetTempFileName(). I had encountered this error once before. But this time I took the time to digg a little deeper into the problem. I discovered that it has to do with EpiServer Community creating temp files for parts of it's configuration and failing to removing them. In my case they contain the configuration section for EpiServer.Common. but it has stripped out all the contents exept the <providers> and the <supportedTypes> section.


When looking into why we get the exception MSDN has some information for us. Under remarks we can read

This method creates a temporary file with a .TMP file extension.The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.
The 65535 number comes from the hex FFFF, so if you look in the C:\WINDOWS\TEMP folder you will probably find a file called tmpFFFF.tmp. You can remove all those files and you'l have a running site.