This project is read-only.

CreateCellComment gives System.ArgumentException: An item with the same key has already been added.

May 6, 2013 at 12:23 PM
This happens only in some cells now and my template worked fine before this few weeks.
  public static void SetComment(ref ISheet w, int row, int col, string text)
    {
        try
        {
            w.GetRow(row).GetCell(col).RemoveCellComment();
        }
        catch (Exception ex) {
        }

        if (text != "")
        {

            if (col < 200)
            {
                    IDrawing d = w.CreateDrawingPatriarch();
                    IComment comment = d.CreateCellComment(new HSSFClientAnchor(0, 0, 0, 0, col, row, col + 4, row + text.Split('\n').Length));
//Exception happens above
                    comment.Author = "CRM";
                    comment.String = (new HSSFRichTextString(text));
                    if (w.GetRow(row).GetCell(col) != null) w.GetRow(row).GetCell(col).CellComment = comment;
            }
        }
    }


Stack trace:

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
at NPOI.HSSF.Record.EscherAggregate.AddTailRecord(NoteRecord note)
at NPOI.HSSF.UserModel.HSSFComment.AfterInsert(HSSFPatriarch patriarch)
at NPOI.HSSF.UserModel.HSSFPatriarch.OnCreate(HSSFShape shape)
at NPOI.HSSF.UserModel.HSSFPatriarch.CreateComment(HSSFAnchor anchor)
at NPOI.HSSF.UserModel.HSSFPatriarch.CreateCellComment(IClientAnchor anchor)
at CashflowUpdater.XSSFProgram.SetComment(ISheet& w, Int32 row, Int32 col, String text) in


What could be wrong?