I am adding items to string list and i know there is data that exists to insert but i keep getting the null reference error message Object reference not set to an instance of an object.
public class ExcelRow
{
public List<String> lstCells;
public byte[] rowHash;
......
}
public class ExcelInfo
{
public List<ExcelRow> excelRows;
}
public ExcelInfo ReadExcel(OpenFileDialog openFileDialog)
{
var _excelFile = new ExcelQueryFactory(openFileDialog.FileName);
var _info = from c in _excelFile.WorksheetNoHeader() select c;
ExcelRow excelRow;
ExcelInfo resp;
resp = new ExcelInfo();
foreach (var item in _info)
{
excelRow = new ExcelRow();
excelRow.lstCells.Add(item.ElementAt(0));
excelRow.lstCells.Add(item.ElementAt(1));
excelRow.lstCells.Add(item.ElementAt(2));
excelRow.lstCells.Add(item.ElementAt(3));
.....
excelRow.CalculateHash();
resp.excelRows.Add(excelRow);
}
return resp;
}
This is where i am getting the error: excelRow.lstCells.Add(item.ElementAt(0));