Search
Thursday, December 20, 2001 ..:: Home ::.. Register  Login
   Calendar  
     
  
   Search  
     
  
   Disclosure  
     
  
   TechTidBits (Blog)  

Are you getting an IOException on Path.GetTempFileName()? Debugging tells you it's creating an empty ("") filename in the exception?

Apr 6

Written by:
Monday, April 06, 2009 9:06 PM  RssIcon

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?

Exception at runtime

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.

Too many temp files

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.

Too many temp files

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)

Tags:
Categories:
Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
     
  
Copyright 1999-2012 by PCHenry.com   Terms Of Use  Privacy Statement