codeflood logo

A generic error occurred in gdi+

I had the above error the other day when using a new install of Sitecore. At first the error doesn’t seem to reveal much, and it quite … generic :) . This was happening when I was trying to create a new rendering through the developer centre in the Sitecore desktop. The full error was:

gdi error

And the error is logged in the log file as well.

Exception: System.Runtime.InteropServices.ExternalException
Message: A generic error occurred in GDI+.
Source: System.Drawing
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
  EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at Sitecore.Resources.FileIcon.GetIcon(String extension, Int32 width,
  Int32 height, Color background)
at Sitecore.Resources.FileIcon.GetIcon(String extension, ImageDimension dimension)
at Sitecore.Resources.FileIcon.GetFileIcon(String filename,
  ImageDimension dimension)
at Sitecore.Data.DataProviders.FileSystemDataProvider.GetItemFields
  (ItemDefinition itemDefinition, VersionUri version, CallContext context)...

For those that don’t know, GDI+ is basically the .net drawing subsystem. It is a hook into the Windows GDI subsystem. Normally when you start getting errors in GDI+ it indicates a low level problem, or some bad parameters or something.

And if we start to read the stack trace above we can see that an Image was being saved when the error occurred. But all I was doing was creating a new rendering. That’s not an image. And this error happens when the dialog tried to open before I have a chance to even select anything. I know from playing with the wizards in Sitecore’s Sheer UI that each wizard view can have an associated image which is displayed. That’s the only image I could think of in this instance.

The error occurred when trying to save the image. What could cause an error in that case? The first thing that came to mind was file permissions. If I don’t have permissions to write to a location, that might cause an error. And that’s exactly what was happening. The account under which ASP.NET was running didn’t have permissions to write to the “temp” folder under the root of the website. I adjusted the permissions so the account could write there, and voila, the error was gone.


just thought i’d give you the heads up…
this error is also quite common when trying write a resized PNG file to a memory stream which is caused by only using a one way seekable stream (the response stream)
more info:

Comments are closed


Leave a comment

All fields are required.