OverflowException happens when calling worksheet.ConvertToImage()

Hello,

As I understand, XlsIO is currently not supporting to convert a GroupShape type to image, so I tried to implement it myself by convert a range of worksheet to image by the following call:

Image image = worksheet.ConvertToImage(1, 1, groupShape.BottomRow, groupShape.RightColumn)

(Please see my attached file for more details)

However, I always get below exception:​ (Always be able to reproduce with my attached file)

System.OverflowException: Overflow error.

at System.Drawing.Graphics.CheckErrorStatus(Int32 status)

at System.Drawing.Graphics.DrawPath(Pen pen, GraphicsPath path)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.DrawShapeFillAndLine(GraphicsPath graphicsPath, ShapeImpl shape, Pen pen, Graphics graphics, RectangleF bounds)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.DrawShape(ShapeImpl shape, WorksheetImpl sheet, Graphics graphics)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.DrawShapes(IShape[] shapes, WorksheetImpl sheet, Graphics graphics, Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn, ItemSizeHelper rowHeightGetter, ItemSizeHelper columnWidthGetter)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.DrawShapes(IShape[] shapes, WorksheetImpl sheet, Graphics graphics, Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn, ItemSizeHelper rowHeightGetter, ItemSizeHelper columnWidthGetter)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.ConvertToImage(Image image, WorksheetImpl sheet, Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn, ItemSizeHelper rowHeightGetter, ItemSizeHelper columnWidthGetter, Int32 width, Int32 height, Stream outputStream)

at Syncfusion.XlsIO.Implementation.WorksheetImageConverter.ConvertToImage(WorksheetImpl sheet, Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn, ImageType imageType, Stream outputStream, EmfType emfType)

at Syncfusion.XlsIO.Implementation.WorksheetImpl.ConvertToImage(Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn)

Any suggestions to resolve this issue?


Many thanks,


Attachment: WpfApp1_dcc317f5.zip


3 Replies

MM Mugil Murugan Syncfusion Team May 10, 2024 12:08 PM UTC

Hi,
 

We have reproduced the reported issue at our end and validating it currently. We will share the validation details on May 14, 2024. 
 

Regards,

Mugil M.



MM Mugil Murugan Syncfusion Team May 14, 2024 12:54 PM UTC

Hi,
 

We have confirmed the issue as "Stack overflow exception is thrown in worksheet to Image conversion"  and logged a defect report. We will include the fix for this issue in our upcoming weekly NuGet release scheduled for May 28, 2024.

 

You can track the status of the defect report through feedback link.

Regards,
Mugil M.



MM Mugil Murugan Syncfusion Team May 28, 2024 01:14 PM UTC

Hi,
 

We appreciate your patience.


We have included the fix to resolve the issue "Stack overflow exception is thrown in worksheet to Image conversion" in our weekly NuGet release version 25.2.6. Kindly upgrade your Syncfusion packages to this new 25.2.6 version and let us know if the issue is resolved. Also, please use the below mentioned code snippet instead of using “if (worksheetShape is GroupShapeImpl groupShape)” in the program.


NuGet Package: NuGet Gallery | Syncfusion.XlsIO.Wpf 25.2.6

Code Snippet:

if (worksheetShape is GroupShapeImpl groupShape &&  groupShape.Height > 0 &&  groupShape.Width > 0)


Root cause of the issue:

When serializing the shape, XlsIO does not check whether the shape height and shape width are greater than zero, which causes a stack overflow exception to be thrown.


Regards,
Mugil M.


Loader.
Up arrow icon