Wednesday, May 13, 2009

A generic error occurred in GDI+ - Solution

Solution for Error: A generic error occurred in GDI+


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. 

Cause of Error: Trying to access invalid path or Trying to save image for path that doesn't exist.
Example:  I was trying to perform following

imgThumbnailImage = imgOriginalImage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

imgThumbnailImage.Save(Server.MapPath(thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);

Wherein thumbnailImagePath will defer when you are trying to perform operation in sub directories.
i.e.  Directory Structure.
Web Application Root
 |----- ImageFolder
 |----- UserWork Folder
             |------ Tried to access ImageFolder which was in Root directory


Solution of Error: Try to access right directory path for image.  Now following path points to root directory where actual image exist.

imgThumbnailImage = imgOriginalImage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

imgThumbnailImage.Save(Server.MapPath("..\\" + thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);

No comments:

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape