My blog is named after one of the most frustrating types of errors we get in programming, the generic one. This particularly nasty specimen is a common one from .Net:
Since I've seen a few Google searches head my way looking for a fix I thought I'd give a few tips. Here's the code that I used to generate this error:
static void Main()
{
Image image = Image.FromFile("Sample.jpg");
image.Save("ConsoleApplication1.exe");
}
Wow, that's a pretty cryptic error for 2 lines of code. The key is the filename passed in the second line, "ConsoleApplication1.exe", it's the name of the application we're running and of course you are not going to be able to save an image to it...
The most common cause of "A generic error occurred in GDI+" is that the application does not have permission to write to the filename you gave it.
In my experience of course. Here's some common things to check if you think this is your problem:
- Is the file in use.
- Does the user your application is running as have write permission to the file / folder.
- Are you running in a restricted environment (e.g. ASP.Net medium trust), and trying to write to somewhere you shouldn't (e.g. the Windows folder).
- Is there enough disk space.
Generic errors are especially nasty because not only do they present a problem with no hint of a solution, they also give you the impression that the original developer didn't know either. This case seems common enough that the developer should have been able to provide a better error message. In my opinion it's a serious twinkie denial condition for Microsoft.
If you've encountered any other interesting generic errors I've love to hear about them.
03/12/2008 10:49 PM (UTC -08:00)