Iterative copying of Worksheets leads to error since version 31.2.3

I am generating an Excel Workbook for Results if my application's calculations. Therefore I create the workbook, then I iteratively copy worksheets for groups of results. This works fine until version 31.2.2, I suddenly get an error after creating the third copy since version 31.2.3:

The code snippet of my method looks something like this:

foreach (var spreadsheetName in spreadsheetNames)
{
var worksheet = workbook.Worksheets.AddCopy(GetFirstOrCreateWorksheet(workbook));
worksheet.Name = spreadsheetName;
}

protected static IWorksheet GetFirstOrCreateWorksheet(IWorkbook workbook)
{
    lock (LockObj)
    {
        return workbook.Worksheets.FirstOrDefault() ?? workbook.Worksheets.Create();
    }
}

The occuring StackTrace shows the following exception:

System.ArgumentException

An item with the same key has already been added. Key: Syncfusion.XlsIO.Implementation.WorksheetImpl

System.ArgumentException: An item with the same key has already been added. Key: Syncfusion.XlsIO.Implementation.WorksheetImpl
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at Syncfusion.XlsIO.Calculate.CalcEngine.RegisterGridAsSheet(String refName, ICalcData model, Int32 sheetFamilyID)
   at Syncfusion.XlsIO.Implementation.WorksheetImpl.EnableSheetCalculations()
   at Syncfusion.XlsIO.Implementation.Collections.WorksheetsCollection.Add(IWorksheet sheet)
   at Syncfusion.XlsIO.Implementation.Collections.WorksheetsCollection.AddCopy(IWorksheet sheet, ExcelWorksheetCopyFlags flags, Boolean isLocal)
   at Syncfusion.XlsIO.Implementation.Collections.WorksheetsCollection.AddCopy(IWorksheet sheet, ExcelWorksheetCopyFlags flags)
   at Syncfusion.XlsIO.Implementation.Collections.WorksheetsCollection.AddCopy(IWorksheet sheet)

3 Replies

KS Karthika Santhana Krishnan Syncfusion Team October 31, 2025 07:23 AM UTC

Hi Clemens,

 

The reported issue has been resolved, and the fix will be included in the upcoming weekly NuGet release scheduled for November 4, 2025.

 

Regards,

Karthika



CT Clemens Tomsic November 3, 2025 08:45 AM UTC

Hi Karthinka,

thank you for the quick response and fix. I'm looking forward to it.

Regards,

Clemens



GP Gowtham Ponraj Syncfusion Team November 4, 2025 05:42 AM UTC

Hi Clemens,

We appreciate your patience.

 

We have included the fix to resolve the issue in our weekly NuGet release version 31.2.5. Kindly upgrade your Syncfusion packages to this new 31.2.5 version and let us know if the issue is resolved.


Regards,
Gowtham.


Loader.
Up arrow icon