Having read many threads on here about not using double dots when referencing excel com objects, I decided to implement it.
It worked up until I came to doing in my loop.
Here is my loop. Note that it works if I comment this out:
for (int i = 1; i < dgv.Columns.Count + 1; i++)
{
excelWorkbook.Cells[1, i] = dgv.Columns[i - 1].HeaderText;
var cell = excelWorkbook.Cells[1, i];
var fontSetter = cell.Font;
fontSetter.Bold = true; //Bolds the header row
// Garbage collecting
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(fontSetter);
Marshal.FinalReleaseComObject(cell);
}
Shouldn't my code dispose of them variables correctly?
Here is my full code:
[Code removed]
I am trying to follow the steps over at How do I properly clean up Excel interop objects? (the second answer)