Pinu
Pinu

Reputation: 7520

A generic error occurred in GDI+

A generic error occurred in GDI+

[ExternalException (0x80004005): A generic error occurred in GDI+.] System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +615257

I have a webpage in which a pdf is converted to png, and using the response.outputstream it is displayed. when i run this on my local machine is works fine. but when i run the same code on server is throws this exception.

my question is , where i could look in for error. as there is no inner exception or any other information provided. only clue is that it's happening on Image.Save , but the same code works perfectly fine on my local machine , then y is it not working on production???

http://blog.maartenballiauw.be/post/2008/05/13/ASPNET-MVC-custom-ActionResult.aspx

this is the example i am following

Upvotes: 2

Views: 10430

Answers (7)

Jirka Helmich
Jirka Helmich

Reputation: 106

This worked for me. Writing to MemoryStream and then Write the MemoryStream to the Output. Reasoning and code is here: https://weblog.west-wind.com/posts/2006/Oct/19/Common-Problems-with-rendering-Bitmaps-into-ASPNET-OutputStream

Upvotes: 4

River Satya
River Satya

Reputation: 1099

This happened for me when the file already existed. Deleting the file before save resolved the problem. What an incredibly unhelpful error message.

Upvotes: 0

Jerin
Jerin

Reputation: 11

I installed my application on a Windows 7 machine by running as administrator.

This worked for me.

Upvotes: 1

Pinu
Pinu

Reputation: 7520

I changed my Image over load method to

Image.Save(context.HttpContext.Response.OutputStream, ImageCodecInfo encoder, EncoderParameters encoderParams)

earlier i was using Image.Save(context.HttpContext.Response.OutputStream,ImageFormat)

after changing the overload method for save , it fixed the error.

Upvotes: 3

Coding Flow
Coding Flow

Reputation: 21881

It is probably that the asp.net worker process does not have permision to create a file where you are trying to save the image on the server.

Upvotes: 0

PaulB
PaulB

Reputation: 24422

I had something similar a while back ... usually to do with security. Don't copy the png over from dev, (if you have one) the server probably won't be able to overwrite and make sure the asp proccess has write access to the dir you're attempting to save to.

Upvotes: 0

StingyJack
StingyJack

Reputation: 19479

Take a look at the big "Caution" note in the System.Drawing documentation. All kinds of weird stuff can happen when you use something intended for desktop processing in a service process.

Check the usuals like permissions, path existence, framework version, etc.

Upvotes: 4

Related Questions