Saturday, February 28, 2009 9:23 PM anas

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.

Filed under: , ,

Comments

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

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 by Uwe

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.

# re: Solving "A generic error occurred in GDI+" exception.

Saturday, February 28, 2009 3:57 PM by anas

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.

# re: Solving "A generic error occurred in GDI+" exception.

Saturday, February 28, 2009 4:18 PM by SGWellens

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 by peSHIr

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. ;-))

# re: Solving "A generic error occurred in GDI+" exception.

Monday, March 02, 2009 3:08 AM by anas

Hi peSHIr,

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

# re: Solving "A generic error occurred in GDI+" exception.

Thursday, March 19, 2009 3:43 PM by plan17b

Everytime I have run into it, it means

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

# re: Solving "A generic error occurred in GDI+" exception.

Thursday, May 07, 2009 2:26 PM by Mike

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!

# re: Solving "A generic error occurred in GDI+" exception.

Sunday, August 02, 2009 3:11 PM by Phil

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

# re: Solving "A generic error occurred in GDI+" exception.

Tuesday, October 13, 2009 10:44 AM by Matías Ram

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

# re: Solving "A generic error occurred in GDI+" exception.

Thursday, October 29, 2009 10:47 AM by SunandaSh

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.

# re: Solving "A generic error occurred in GDI+" exception.

Tuesday, December 01, 2009 3:20 AM by Dean

Maybe this will help. I know it solved the problem for me:

support.microsoft.com/Default.aspx

# re: Solving "A generic error occurred in GDI+" exception.

Thursday, March 18, 2010 1:47 PM by MARK

Hello:

May anyone help on this?

I am having the same exception ("A generic error occurred in GDI+").

Yet i am not running an asp but a windows form application, it basically takes a picture form a camera installed in the pc and stores it in a network folder.

Now this is what its strange, the application runs well in all the pcs of the network but one, that throws the exception.

Still it is not a permission issue, because i checked that the folder has the everyone in full control so...

Are there any other causes for these to appear more based on hardware then other thing?

Leave a Comment

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