Thursday, September 04, 2008

GetTempFileName bad behaviour

If you call System.IO.Path.GetTempFileName it will create a file of the form tmpXXXX.tmp where the hex suffix can run from 0000 to FFFF.

If Windows runs out of names it throws an IOException with the thoroughly unhelpful message: "The file exists". Which file? Where? So what?

I realize that this is the documented behavior - it's just crap. Especially given that this problem is incredibly unlikely to happen on the bench, and could be caused by another program hogging all the names before your poor application comes along. At the very least throw an exception with a meaningful message to allow some hope of diagnosing the problem in the field.

No comments: