Occasional "An error occurred while processing the spreadsheet request: A generic error occurred in GDI+." errors when exporting a shape to an image

The stack trace relative to the aspose library is this:

at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at ??.?.??()
at ?.?.ToImage(String , ImageFormat , Chart )
at Aspose.Cells.Charts.Chart.ToImage(String imageFile, ImageOrPrintOptions options)
at ..ToImage(String , ImageOrPrintOptions , Shape )

This runs as part of a .Net MVC application where I convert shapes to images that are saved in a folder on the server. The security permissions are all ok.

In the past this error occurred occasionally after I deployed the app without restarting the web server. I also found this: c# - A Generic error occures when saving images using WebService - Stack Overflow which seems to indicate it is a security permissions issue.

Any ideas of what else might cause this error ?


Hi Costa,

Thank you for contacting Aspose support.

I am afraid, it is hard to detect the problem cause unless we are able to replicate the said exception on our end therefore we would request you to please share a sample application (along with its dependencies & input sample spreadsheet) for thorough investigation.

By the way, I have searched through our defect database to find similar incidents logged in past. I have noticed a few tickets where customers have reported same exception while saving spreadsheets to raster image formats. Most of the aforesaid incidents were caused due to the size of the resultant image where the resultant canvas was unable to accommodate all the data from a worksheet or workbook. Your presented scenario seems to be different so it would be of great help if you can share the sample application along with the spreadsheet that contains the shapes causing the problem.

The issue went away. At this time I don’t have a sample application and I was looking more for ideas. If I could reproduce this consistently I would post a sample.

We will keep an eye on it, for now.

Thank you!


Most of the aforesaid incidents were caused due to the size of the resultant image where the resultant canvas was unable to accommodate all the data from a worksheet or workbook.

Is there any post on the forum that you can point me to that contains the scenario you described in this statement?

Also, is there an image size limit beyond which the library would error?


Hi Costa,

Unfortunately, all the forum threads that I have mentioned in my comments are private so you will not be able to review the communication on those threads. However, I have quoted some contents here for your reference. Please note, all below mentioned scenarios were logged against the exception message "A generic error occurred in GDI+ ".

Scenario 1: Customer reported the issue for WorkbookRender.ToImage. The ticket attached to this scenario was marked as Won’t Fix.

However, even with the latest version of Aspose.Cells, I still receive an exception. Here are the details:

Inner Exception: null
Error Code: -2147467259
Message: A generic error occurred in GDI+
Source: System.Drawing
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at ˆŸ.š.‡”(Bitmap bitmap, Byte[]& bitmapData, Int32& stride)
at Š.“.™(Bitmap )
at Š.”.™ˆ(Int32 , ImageOrPrintOptions )
at Š.”.šˆ(Stream , ImageOrPrintOptions )
at Aspose.Cells.Rendering.WorkbookRender.ToImage(String filename)
at DoxTekFileConversions.FileConversions.ConvertEXCEL(String file, Boolean deleteOrig, String newFileDir) in C:\TFS\Other\Dev\DoxTekFileConversions\DoxTekFileConversions\FileConversions.cs:line 185

Could this be something environmental affecting the saving of the converted image?

We initially got out of memory exception while running your project but when we changed it to latest version, then we got Generic GDI+ Error exception. The exception might be occurring because you have set one page per sheet property to true and one of your sheet has 21 pages. If there are huge number of pages, then it is not possible to create the entire worksheet into a single page.
Scenario 2: Issue was reported for XLSX to PDF conversion. The ticket attached to this scenario was resolved with Aspose.Cells for .NET

I have an XLSX file we're trying to convert to PDF, but the conversion is resulting in:

Aspose.Cells.CellsException: A generic error occurred in GDI+.
Scenario 3: This scenario was hard to replicate because it was happening on only Windows XP without any service pack installed and while setting specific properties for rendering spreadsheets to TIFF format. The ticket attached to this scenario was logged for v7.0.3.4 and is still unresolved but the customer reported he was no longer experiencing the problem with immediate next release.
As per my post number 157, I am applying the below settings before rendering the excel book to image.

· Auto fit columns
· Auto fit rows
· Print area
· BlackAndWhite
· Orientation
· Print Grid lines
· Print Headings
· Order
· PrintTitleColumns
· PrintTitleRows
· Print hidden rows
· Print hidden columns

When I comment out the auto fit columns codes in my class, the tiff conversion is working fine. But if I auto fit the columns I am getting “An Error occurred in GDI+.” Exception. Please explain me what is happening while auto fitting the columns and what is the relation between auto fit columns and tiff compression (Aspose.Cells.Rendering.TiffCompression.CompressionNone).