Anas Ghanem

ASP.NET from the middle east

Syndication

Sponsors

News


    Subscribe in a reader
Solving "A generic error occurred in GDI+" exception.
 

Hi,

If you are getting that error , then I can say that your application doesn't have a write permission on some directory.

For example, if you are trying to save the Image from the memory stream to the file system , you may get that error.

I also faced that error when I was using Infragistics charts control , the control was trying to create a temporary chart in ChartImages folder and my application was not given the write permission.

Please if you are using XP, make sure to add write permission for the aspnet account on that folder.

If you are using windows server (2003,2008) or Vista, make sure that add write permission for the Network service account.

Hope it help some one.

Published Saturday, February 28, 2009 9:23 PM by anas
Filed under: , ,

Comments

# Solving "A generic error occurred in GDI+" exception. - Anas Ghanem@ Saturday, February 28, 2009 2:55 PM

Pingback from  Solving "A generic error occurred in GDI+" exception. - Anas Ghanem

# re: Solving "A generic error occurred in GDI+" exception.@ Saturday, February 28, 2009 3:44 PM

Na, _one_ of the possible errors could be the one, you described.

The "Generic error" in fact is used in certain scenarios. It means "we were to lazy to write better error return code".

This really sucks.

by Uwe

# re: Solving "A generic error occurred in GDI+" exception.@ Saturday, February 28, 2009 3:57 PM

Well, at least that's based on my experience and on the problems i faced.

I know that there is many other causes of that problem,but that's what i know until this time.

by anas

# re: Solving "A generic error occurred in GDI+" exception.@ Saturday, February 28, 2009 4:18 PM

I think it's the most common error so permissions should always be checked first.

# re: Solving "A generic error occurred in GDI+" exception.@ Sunday, March 01, 2009 5:54 AM

It might not be that you don't have write permissions, but a sharing violation might be in effect.

Common scenario that this happens:

1) Read an image into a Bitmap object

2) Manipulate the bitmap

3) Wanting to write back the bitmap to overwrite the original image file you read in step 1.

This can happen because the Bitmap implementation seems to be as lazy as possible. It can choose the just remember the path that was the source of the image bits (or even a handle to the opened file they came from). This then means your software has the original image file open, causing this problem when you try to overwrite it in step three.

To work around this use some simple code in an intermediate step (let's say 1a) that creates a new, blank Bitmap object with the same width/height/colordepth as the image you read. Then, get a Graphics object for the blank image and draw (BitBlt, basically) the loaded image onto the blank image. Then, dispose the loaded image. This gets you a Bitmap object that contains the content of the loaded image actually stored in memory, without any link to the original image file. Then, work on the Bitmap the way you like and you can easily save it back over the original file in step 3 without sharing violations. (If you have write permissions, of course. ;-))

by peSHIr

# re: Solving "A generic error occurred in GDI+" exception.@ Monday, March 02, 2009 3:08 AM

Hi peSHIr,

Thanks for information! I really appreciate it and hope it will help someone in the future.

by anas

# re: Solving "A generic error occurred in GDI+" exception.@ Thursday, March 19, 2009 3:43 PM

Everytime I have run into it, it means

"You used an invalid path to save a bitmap file."

by plan17b

# re: Solving "A generic error occurred in GDI+" exception.@ Thursday, May 07, 2009 2:26 PM

Of course that was it! Why wouldn't it be? For your reference, I've written a nice bit of GDI code to make address labels, and we were porting it to ASP. Got the dreaded "generic error" in GDI+ when I tried to save to the webdir using a Bitmap class derived from the GDI hBitmap. Of course, ASP docs were of zero help, but your page got me up and running right away. I probably should've discovered it myself, but I am an API applications programmer, and it simply never occurred to me that it would be that easy!

T H A N K S  H E A P S  Anas!

by Mike

# re: Solving "A generic error occurred in GDI+" exception.@ Sunday, August 02, 2009 3:11 PM

Thanks for the advice!  I never would have thought such a 'general' error had to do with a filesystem issue!  The engineer who came up with that error message deserves a demotion! :)

Thanks,

PHil

by Phil

# re: Solving "A generic error occurred in GDI+" exception.@ Tuesday, October 13, 2009 10:44 AM

I have the same problem, GDI+ exception.

But i resolve, when change the property visible to false from the char.

Later i will fill the grafic from the page with a dataset.

I hope for with solucion resolve your problem

by Matías Ram

# re: Solving "A generic error occurred in GDI+" exception.@ Thursday, October 29, 2009 10:47 AM

I have this error while using AlternateView and LinkedResource for taking an image and using it in the mail and sending it using System.net.mail. Since i am using two images I am making a collection of linkedResource -

Dim collection As LinkedResourceCollection = hmtlView.LinkedResources()

               collection.Insert(0, background)

               collection.Insert(1, EmpImage)

               hmtlView.LinkedResources.Concat(collection)

               mailMessage.AlternateViews.Add(hmtlView)

I get this exception here - A generic error occurred in GDI+

Please help me with your suggestions.

Leave a Comment

(required) 
(required) 
(optional)
(required)