We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

'System.StackOverflowException' in SheetRender.ToImage(0- file)

When performing a SheetRender.ToImage we are receiving a Stack overflow in Aspose.Cells.dll


I have verified that this is not a looping issue, it is a very simple app to test things out. However, the worksheet is pretty complex with a lot of objects and conditional formatting.

The code works fine for most of the worksheets but is crashing on this one.

What can I provide to help uncover the issue here?

Below is the code (not pretty for now), just for the sake of it:
String newImageName = theWorksheet + “_” + stripColon(theRange) + “.png”;

String imageFilePath = Server.MapPath("~\\Images\\tiles\\");

String imageFile = imageFilePath + newImageName;


// Get a new bitmap image of the represented chart.

Workbook wb = new Workbook(thePath + "\\" + theWorkbook);

Worksheet ws = wb.Worksheets[theWorksheet];

PageSetup ps = ws.PageSetup;

ps.LeftMargin = 0;

ps.RightMargin = 0;

ps.TopMargin = 0;

ps.BottomMargin = 0;

ps.CenterHorizontally = true;

ps.CenterVertically = true;


ps.PrintArea = theRange;

//Define ImageOrPrintOptions

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

//Specify the image format

imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

//Only one page for the whole sheet would be rendered

// -- OBSOLETE imgOptions.IsImageFitToPage = false;

imgOptions.OnePagePerSheet = true;

//imgOptions.OnlyArea = true;

imgOptions.IsImageFitToPage = true;

imgOptions.OnlyArea = true;

//Render the sheet with respect to specified image/print options

SheetRender sr = new SheetRender(ws, imgOptions);

//Render the image for the sheet

try

{

sr.ToImage(0, imageFile); // CODE DIES HERE.

}

catch (Exception e)

{

}


Hi Dan,


Thank you for contacting Aspose support.

As you have mentioned that the presented scenario seems to occur with a specific spreadsheet therefore we suspect that the problem is template specific. Please provide us the problematic spreadsheet so we could evaluate the problem, and move forward to log it for correction purposes. Before you do that, please give the latest version of Aspose.Cells for .NET 8.0.2 a try on your end to see if it makes any difference.

Unfortunately the latest version did not help.


I am working to get a stand alone version of our worksheet that is creating the issue. I hope to have it to you shortly.

Hi Dan,


Sorry to know that the latest build didn’t help in your particular scenario. We will be looking forward to hear from you soon.

Hi Dan,


Just to let you know that we have received your sample spreadsheet (via an email), and we are currently looking into it. We will shortly respond back with updates in this regard.

Hi again,


Thank you for your patience.

Unfortunately, we are unable to replicate the System.StackOverflowException with your provided sample. Although we have observed CellsException: “Arithmetic operation resulted in an overflow” while rendering the worksheet “B2-ProductView” to image with specified PrintArea (A2:AI92). We have logged this problem in our bug tracking system under ticket Id CELLSNET-42649 for further investigation and correction purposes.

In order to investigate the originally posted problem (System.StackOverflowException), we would request you to please share the complete spreadsheet. You may use the same mechanism (via an email) to share any private data with us. Please note, we request for samples to replicate the problem on our end. As soon as the reported problem is fixed, and a release containing the fix is available for public use, we delete all customer shared data. For further assurance, please check EULA for NDA (clause 8).

Please feel free to write back in case you have any concerns.

Good, that you were able to create the one error – I also had this error when reducing the number of worksheets down to just the 2. I believe that if this issue is fixed there is a good chance it will also resolve the other, worse error of the StackOverflowException.


I am working with out team to send you the full worksheet which creates the primary issue.
Thanks for the prompt attention.


Hi Dan,


Thank you for sending the complete spreadsheet for our testing. Unfortunately, we are unable to replicate the “StackOverflowException” using the following piece of source code. Instead, the code is producing the image as per expectation. We will send the image via a private message.

C#

Workbook wb = new Workbook(myDir + “Product Capability Burndown MER 5.1.14_DAN.xlsm”);
wb.CalculateFormula();
Worksheet ws = wb.Worksheets[“B2-ProductView”];
PageSetup ps = ws.PageSetup;
ps.LeftMargin = 0;
ps.RightMargin = 0;
ps.TopMargin = 0;
ps.BottomMargin = 0;
ps.CenterHorizontally = true;
ps.CenterVertically = true;
ps.PrintArea = “A2:AI92”;


//Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
//Specify the image format
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
//Only one page for the whole sheet would be rendered
// – OBSOLETE imgOptions.IsImageFitToPage = false;
imgOptions.OnePagePerSheet = true;
imgOptions.IsImageFitToPage = true;
imgOptions.OnlyArea = true;
//Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(ws, imgOptions);
//Render the image for the sheet
try
{
sr.ToImage(0, myDir + “output.png”); // CODE DIES HERE.
}
catch (Exception e)
{
Console.WriteLine(e);
}

Please note, we have evaluated the presented scenario while using the latest version of Aspose.Cells for .NET 8.0.2 (assembly from net2.0 folder), target framework 2.0 on Windows 7 Home Premium 64-bit platform.

We would request you to give the latest version another try using the code snippet provided in this post. In case the problem persists, please provide us the environment details so we could simulate your environment to re-evaluate the problem on our end. Please note, we are interested in the following information,

  • Operating System version
  • Operating System Architecture (32bit/64bit)
  • Target Framework
  • Application Type

That is odd that you are not having the same issue.


I was originally using Aspose.Cells for .Net\Bin\net3.5\Aspose.Cells.dll
I changed to Aspose.Cells for .Net\Bin\net2.0\Aspose.Cells.dll and still have the problem.
The Runtime Version is v2.0.50727 and the Version is 8.0.2.0 (as shown within the Properties of the Reference section of the solution.

I am running Windows 7 Home Premium 64-Bit.
The Target Framework is currently set to .Net Framework 4.5 (Do I need to change this to 2.0? - It will create some issues if I do.

Also, is there a reason to use the net2.0 versus the net3.5 version?

I would like to also add…


I was looking at the code you replied with. I saw that you added wb.CalculateFormula();

When I added this call, I got the Stack Exception here. I also tried the call with the ignoreError flag set to true, same problem.

Hi Dan,


We are already using the same environment as of yours but still we are unable to replicate the exception on our end. Moreover, we have tested by changing the target framework to 2.0, 3.0, 3.5, 4.5 & 4.5.1, and while using the assemblies from different folders of Aspose.Cells installation directory. Unfortunately, the exception didn’t occur even once otherwise we would have logged the problem in our bug tracking system providing the stack trace.

Regarding the different Aspose.Cells assemblies, as mentioned in the readme.txt provided with Aspose.Cells for .NET package, if you are targeting .NET 3.5 or 4.0, you should be using the assembly from the net3.5 folder. For all other frameworks with exception of Client Profile, you should use the assembly from net2.0 folder. I have attached the aforesaid readme.txt with this post for your reference.

Please provide the complete stack trace of the exception that you are getting on your end so we could try to troubleshoot the problem based on the stack trace. Please also confirm that you are loading the same spreadsheet that you have provided to us.

I have verified each of my assemblies. I went back and created a single page aspx file with a single image and the call to the function above. When I use the wb.CalculateFormula I get the “unhandled exception of type ‘System.StackOverflowException’ occured in Aspose.Cells.dll”


The troubleshooting steps I get mentioned are looking for an infinite loop or infinite recursion.

There is no way to retrieve the stack trace since the error effectively wipes out the stack. Commenting out the wb.CalculateFormula gets me to the sr.ToImage call where it also dies.

Is there any other dependent libraries that could interfere? Since I am relatively new (very new actually) to the .Net development, is there a way to get more information out of the failed stack overflow result?

Hi Dan,


Thank you for your continues support.

We are able to observe the System.StackOverflowException while using the previously provided code snippet in a simple ASP.NET application. We have logged this problem in our bug tracking system under ticket Id CELLSNET-42651 for further investigation and correction purposes. Please spare us little time to properly analyze the problem cause, and to provide a fix (if applicable) at earliest. In the meanwhile, we will keep you posted with updates in this regard.

Please note, earlier we were testing the presented scenario on a console application that didn’t allow us to observe the System.StackOverflowException. Now we can see the said exception at Workbook.Calculate as well as the SheetRender.ToImage methods, and same has been logged in aforesaid ticket.

Please accept our sincere apologies for the inconvenience caused to you.

I’m glad to hear you were able to repeat the issue. Thanks for continuing to look into this. Looking forward to the results.

Is there any estimate on when a fix for this issue will be resolved?

Additionally, is there an escalation process?
Thanks in advance.

Hi Dan,


Thank you for writing back.

Unfortunately, both ticket attached to this thread are currently pending for analysis and are in the queue with other tasks. We have logged a note for the concerned team member to share the insight of the problems at earliest, and if possible also provide the estimated release schedule for the fix. As soon as we receive any news, we will post here for your kind reference.

Regarding your other question, as you are availing the free support therefore any issue raised by you will be added to a queue that follows the “First Come, First Serve” paradigm. If you wish to escalate the process, you may have to consider any of the paid support subscriptions. Please check out the details for different support options.

We are not averse to paying for priority or better support. Unfortunately this current issue is a complete show stopper for us and does not allow us to proceed. We had purchased another component only to find later it could not do what we needed. The Aspose solution actually comes very close with the exception of this Stack Overflow. This is preventing us from purchasing OEM licenses.


Any help to at least have an indication on this issue or some assurance that if this cannot be fixed in some “reasonable” time, then some type of other arrangements (regarding purchase) can be made.

Please let me know your thoughts,

Thanks for the great support so far,
Dan

Hi Dan,


We have provided the details of the different support options upon your request as you wished to escalate the process of resolving the mentioned ticket.

In reference to StackOverflowException problem, I am afraid, we wont be able to provide an estimated release schedule for the fix unless we have properly analyzed the problem. So far we haven’t heard from the core development team on this matter so I believe the mentioned ticket is in analysis phase at the moment. Please spare us little time, and we will soon get back to you with more updates in this regard.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.0.2.2 and let us know your feedback.

Hi,


Thanks for using Aspose.Cells.

After further investigation of your issue, we found and think the issue “CELLSNET-42651” may be caused by the fact that the default stack size of IIS is too small (256k only). It is not the issue of our component but due to too much small default stack size of IIS. .Please see the sample code for your reference and try to change your code accordingly:

C#

private HttpPostedFileBase file;


[HttpPost]

public ActionResult Index(HttpPostedFileBase file, string mode)

{

this.file = file;

Thread t = new Thread(Calc, 1048576);

t.Start();

t.Join();

return null;

}


private void Calc()

{

if (file != null && file.ContentLength > 0)

{

var wbkMain = new Workbook(file.InputStream);

wbkMain.CalculateFormula();

}

}


Hopefully it will fix your issue.

Thank you.