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 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,
Thanks for confirming the issues, looking forward for quick turn around with the possible fixes.
Hi David,
Hi again,
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.