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

Free Support Forum - aspose.com

StackOverflow when calculating series of formulas

Hello,
I’m using Aspose.Cells for .NET 7.1.2.0. A particular workbook that I’m working with contains a large series of concatenation formulas. I have code that inserts rows then tries to calculate the sheet. It seems like this code runs fine in some 64bit environments, but in 32bit, the call to CalculateFormula() throws an error, at which point the process terminates, before my code has a chance to log the error or handle it in any way. Stepping through with a debugger, I can see that the following error occurs:

An unhandled exception of type ‘System.StackOverflowException’ occurred in Aspose.Cells.dll

[When the problem happens in the context of my web application, the error is reported as occurring in mscorlib.dll.]

I understand that there may be limits to the number of levels of formulas than can be processed, but is there any way that it could be made to fail more gracefully, in a way where the error could be trapped and handled? The code I’m using is here; the spreadsheet is attached.

void IssueWithCalculateCausesOverflow()
{
try
{
var filepath = string.Format("{0}CalculateOverflow5.xls", TestHelper.Folder);
var workbook = new Workbook(filepath, new LoadOptions(LoadFormat.Excel97To2003));

var worksheet = workbook.Worksheets[0];

worksheet.Cells.InsertRows(17, 2);
worksheet.Workbook.CalculateFormula(true);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

We have recently fixed this error.

Please download and use the latest version:
Aspose.Cells
for .NET v7.3.2.1

It should work fine.

I have tested with the above version and found no issue with it. Below is my sample test code.

C#


string filepath = @“F:\Shak-Data-RW\Downloads\CalculateOverflow5.xls”;


var workbook = new Workbook(filepath, new LoadOptions(LoadFormat.Excel97To2003));


var worksheet = workbook.Worksheets[0];


worksheet.Cells.InsertRows(17, 2);

worksheet.Workbook.CalculateFormula(true);

Thank you for your quick response. I tried the newer version and there is no difference. See attached screenshot. The behaviour I described earlier is not exactly correct. I am running on a 64bit (Win7) machine with these results:
- console app: works when platform target is x86 or Any CPU; fails when x64
- web app running in IIS7 Classic mode: works when “Enable 32-Bit Applications” is set to false for the app pool; fails when it is set to true

Hi,


Could you please create a sample project with your desired project/application settings in VS.NET 2008/2010 with v7.3.2.1, zip it and post it here. We will simply run your project and it will help us to trace the issue accurately, so that we could log your issue to figure it out soon.

Thank you.

Here is a console app which I believe produces the error. I’m more concerned about the error in the web app, but that’s a little more difficult to package up. I’m assuming it’s the same issue.

Hi,


Thanks for sharing the VS.NET project whose target platform is set to x64bit.

I have logged a ticket with an id: CELLSNET-41113 for your issue. We will soon look into it to figure it out. Once we have any update on it, or we resolve your issue, we will let you know here.

Thank you.

Hi,


Could you try our latest version/fix: Aspose.Cells for .NET v8.0.1.3 if it fixes your issue. We suggest you to try with a smaller stacksize ( e.g use/set appropriate WorkbookSettings.CalcStackSize in your codes)

Also, your issue might be caused by the fact that the default stack size of IIS is too small (e.g 256k only). Please try to change it, see the sample code for your reference:
e.g
Sample code:

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

}

}


Thank you.