Aspose.Cells.PutValue throws error when executed in Parallel.Foreach Method

Hi Team,

Currently we are using Aspose.Cells Dll version 8.5.1.0 in our project, it includes code to write large amount of values in Excel Workbooks, using Cells.PutValue Method executed through Parallel.ForEach Task Library Method.
While writing values to the Excel Sheet the PutValue() Method randomly throws an error “Object reference not set to an instance of an object.”.
This error does not occur in case we move the PutValue() Method out of Parallel.ForEach Method.

Code that throws error with the Parallel.Foreach Invocation
Parallel.ForEach(cellInfos, (cellIn) =>
{
try
{
wb_TestParallel.Worksheets[0].Cells[cellIn.rowCounter, cellIn.columnCounter].PutValue(cellInfos.ToString());
}
catch (Exception ex)
{ }
} );

Code that is working, if move the method out of Parallel.ForEach Execution.
foreach (cellInfor cellIn in cellInfos)
{
wb_TestParallel.Worksheets[0].Cells[cellIn.rowCounter, cellIn.columnCounter].PutValue(cellInfos.ToString());
}

Please let us know, if more details are required for verifying this issue.

Thanks.






Hi,


Thanks for providing us some details.

Please try our latest version/fix: Aspose.Cells for .NET v8.6.1.2

If you still find the issue, kindly create a simple sample console demo application (runnable) with v8.6.1.2, zip it and post us here to show the issue, we will check ti soon. Also provide your template file(s) if you have any.

Thank you.

Thanks Amjad, I also tried with the latest version of the Aspose Dll i.e. 8.6.1.2 , but still the issue persists.
For verifying the issue at your end, I am attaching the code to replicate this issue, please include the below content in any class file and include the class in console application and run the application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Workbook wb_TestParallel = new Workbook();
int rowCounter = 4000;
int columnCounter = 100;
List cellInfos = new List();
for (int rCoun = 0; rCoun < rowCounter; rCoun++)
{
for (int cCoun = 0; cCoun < columnCounter; cCoun++)
{
cellInfos.Add(new cellInfor(rCoun, cCoun));
}
}

// Code that is not working with the Parallel.Foreach Invokation
Parallel.ForEach(cellInfos, (cellIn) =>
{
try
{
wb_TestParallel.Worksheets[0].Cells[cellIn.rowCounter, cellIn.columnCounter].PutValue(cellInfos.ToString());
}
catch (Exception ex)
{
throw ex;
}
}
);
// Code that is working, if move the method out of Parallel.Foreach Execution.
//foreach (cellInfor cellIn in cellInfos)
//{
// wb_TestParallel.Worksheets[0].Cells[cellIn.rowCounter, cellIn.columnCounter].PutValue(cellInfos.ToString());
//}
}
}
class cellInfor
{
public int rowCounter;
public int columnCounter;
public cellInfor(int row, int col)
{
rowCounter = row;
columnCounter = col;
}
public override string ToString()
{
return rowCounter.ToString() +" - " + columnCounter.ToString();
}
}
}

Hi David,


Many thanks for the sample code.

We have evaluated the scenario while using the latest version of Aspose.Cells for .NET 8.6.1.2 and we are able to observe the following two random exceptions at Cell.PutValue method.

1) NullReferenceException: Object reference not set to an instance of an object.

at . . . . (Int32 )
at . . ( , Int32 , Int32 , Int32 )
at . . ( , Int32 , Int32 )
at . . . . (Int32 , Int32 )
at . . (Int32 , Boolean , Boolean )
at . .GetCell(Int32 , Boolean , Boolean )
at Aspose.Cells.Row.GetCell(Int32 , Boolean , Boolean )
at Aspose.Cells.Row.GetCell(RowCollection , Int32 , Boolean , Boolean , Boolean )
at Aspose.Cells.RowCollection.GetCell(Int32 , Int32 , Boolean , Boolean , Boolean )
at Aspose.Cells.Cells.get_Item(Int32 row, Int32 column)
at Cells.Program.<>c__DisplayClass1.b__0(cellInfor cellIn) in Program.cs:line 139

2) CellsException: Cell has been removed:

at Aspose.Cells.Cell. ()
at Aspose.Cells.Cell.PutValue(String stringValue)
at Cells.Program.<>c__DisplayClass1.b__0(cellInfor cellIn) in Program.cs:line 139


This case needs thorough investigation therefore we have logged it in our bug tracking system as CELLSNET-44070. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Thanks for confirming the issues, looking forward for quick turn around with the possible fixes.

Hi David,


Thank you for writing back. Please note, the aforementioned ticket is currently pending for analysis, and is in the queue with other priority tasks. We will update you with results as soon as we have completed the preliminary analysis of mentioned scenario.

Hi again,


We have looked further into the details of the issue logged earlier as CELLSNET-44070. Please note, the problem cause is that the Aspose.Cells APIs do not support manipulating the data models (Worksheets, Cells, Rows, Columns & so on) of one Workbook in parallel. Moreover, we will not be able to provide such support very soon therefore we have closed the aforementioned ticket as Won’t Fix.

Thank you for your understanding.

Thanks for the reply, but did Aspose API supported manipulating Data Model in parallel in the past. As the same code worked with out any issue until we upgraded to version 8.5.1, in past we had worked with version 7.7.2 and 7.2.2.
Also by when can we expect the Data Model Manipulation in Parallel to be supported by Aspose, will we be notified about this change ?

Hi,

AonHewitt DZ:
Thanks for the reply, but did Aspose API supported manipulating Data Model in parallel in the past. As the same code worked with out any issue until we upgraded to version 8.5.1, in past we had worked with version 7.7.2 and 7.2.2.


I have tested this scenario against Aspose.Cells for .NET 7.7.2 & 7.2.2 to recieve NullReferenceException at Cell.PutValue method. Based on these tests, I believe the said feature was not available with these releases. If you are still sure that the code used to work fine then please provide us an executable sample application along with it’s dependencies. Upon reviewing your demo application, we will forward this case to product team again.

AonHewitt DZ:

Also by when can we
expect the Data Model Manipulation in Parallel to be supported by
Aspose, will we be notified about this change ?


As narrated earlier, this feature is not on our road map yet, however, we will check with the concerned team once again to get an estimated time frame, if applicable.

Hi,

Thanks for using Aspose.Cells.

For all versions of our component, the cells model does not support concurrent operations. From 8.0 we change the cells model for better performance (memory and time cost) which also increased the possibility of concurrent problem. That is, comparing with old versions, versions after 8.0 will give such kind of problem more frequently. Anyways, you should never manipulate one workbook in multi-threads environment unless you can synchronize objects for thread safe. For your cases, the experience that user did not get such kind of issue does not mean it is safe always to manipulate cells in this way. Make the synchronization in cells model will surely cause performance issue for most users who do not need the parallel operations, so we have no plan to support this feature in future.