Are you getting an IOException on Path.GetTempFileName()? Debugging tells you it's creating an empty ("") filename in the exception?
Monday, April 06, 2009 9:06 PM
In writing up another blog about Exception handling I was getting some VERY strange results from a path throuhg my code which should be well behaved. Turns out I was getting IOExcpetions where I wasn't expecting them! And why was Path.GetTempFileName() returning an empty string for a temp filename? Read on for a very freaky reason why!
In writing up another blog about Exception handling I was timing a path through my code which should have performed very fast, at least that's what my hypothesis was. OK, I could be wrong (wouldn't ber the first time :>) but this time, I thought NO, I'm not wrong, there's something funky going on here. So down deep I go!
Here's my code, and you see anything wrong with it? Well if you're looking at the Path.GetTempFilName(), you can see there's obviously nothing wrong cause I can compile and run it (screenshot's taken at runtime afterall). So what is going on?
Turns out, by a fluke and creating googling, I found Paul Maddox's blog which led me to check out my temp directory and WOW!!!!!!! Here's what I saw.
WOW! That's 67, 493 files, yup, you read that correctly. WOW! According to Paul, if you have TOO many files, then you're going to get an IOException from Path.GetTempFileName, and that's exactly what I was getting. When I cleaned out my temp dir, things started to work again. Check it out.
AAAAAHHHHHHH THERE we go, a properly named temp file! BEAUTIFUL! Now, time to go grab a coffee and get back to coding my Exception blog! :>
Resources: Paul Maddox: .NET GetTempFileName throws System.IO.IOException: The file exists (12-23-2008)