Version: EPPlus 4.1
After removing a comment from a cell, further accesses to comments on other cells of the same column get unexpected results: either cell.Comment returns null even if a comment is actually present, or ws.Comments.Remove(cell.Comment) throws "Comment does not exist in the worksheet" exception.
Unit tests for bug reproduction (using attached in.xslx):
```
[TestMethod]
public void BugCommentNullAfterRemove() {
string xls = "in.xlsx";
ExcelPackage theExcel = new ExcelPackage(new FileInfo(xls), true);
ExcelRangeBase cell;
ExcelComment cmnt;
ExcelWorksheet ws = theExcel.Workbook.Worksheets[1];
foreach (string addr in "B4 B11".Split(' ')) {
cell = ws.Cells[addr];
cmnt = cell.Comment;
Assert.IsNotNull(cmnt, "Comment in " + addr + " expected not null ");
ws.Comments.Remove(cmnt);
}
}
[TestMethod]
public void BugCommentExceptionOnRemove() {
string xls = "in.xlsx";
ExcelPackage theExcel = new ExcelPackage(new FileInfo(xls), true);
ExcelRangeBase cell;
ExcelComment cmnt;
ExcelWorksheet ws = theExcel.Workbook.Worksheets[1];
foreach (string addr in "B4 B16".Split(' ')) {
cell = ws.Cells[addr];
cmnt = cell.Comment;
try {
ws.Comments.Remove(cmnt);
} catch (Exception ex) {
Assert.Fail("Exception while removing comment at " + addr + ": " + ex.Message);
}
}
}
```
After initial investigation, the problem seems to be in CellStore<T>.Delete, because the content of _commentsStore gets corrupted immediately after the first call to ExcelCommentCollection.Remove.
Same code referencing EPPlus 4.0.5 works fine.
Comments: Fixed in changeset 33392c36678d
After removing a comment from a cell, further accesses to comments on other cells of the same column get unexpected results: either cell.Comment returns null even if a comment is actually present, or ws.Comments.Remove(cell.Comment) throws "Comment does not exist in the worksheet" exception.
Unit tests for bug reproduction (using attached in.xslx):
```
[TestMethod]
public void BugCommentNullAfterRemove() {
string xls = "in.xlsx";
ExcelPackage theExcel = new ExcelPackage(new FileInfo(xls), true);
ExcelRangeBase cell;
ExcelComment cmnt;
ExcelWorksheet ws = theExcel.Workbook.Worksheets[1];
foreach (string addr in "B4 B11".Split(' ')) {
cell = ws.Cells[addr];
cmnt = cell.Comment;
Assert.IsNotNull(cmnt, "Comment in " + addr + " expected not null ");
ws.Comments.Remove(cmnt);
}
}
[TestMethod]
public void BugCommentExceptionOnRemove() {
string xls = "in.xlsx";
ExcelPackage theExcel = new ExcelPackage(new FileInfo(xls), true);
ExcelRangeBase cell;
ExcelComment cmnt;
ExcelWorksheet ws = theExcel.Workbook.Worksheets[1];
foreach (string addr in "B4 B16".Split(' ')) {
cell = ws.Cells[addr];
cmnt = cell.Comment;
try {
ws.Comments.Remove(cmnt);
} catch (Exception ex) {
Assert.Fail("Exception while removing comment at " + addr + ": " + ex.Message);
}
}
}
```
After initial investigation, the problem seems to be in CellStore<T>.Delete, because the content of _commentsStore gets corrupted immediately after the first call to ExcelCommentCollection.Remove.
Same code referencing EPPlus 4.0.5 works fine.
Comments: Fixed in changeset 33392c36678d