I read through quite a few posts on SO regarding this and still need some help understanding this please.
CodeAnalysis is saying this method is disposing objects twice. Actually, it is warning me about this for two objects in the method; once for the file.InputStream
and once for the reader
object
Here is my code:
public void SaveCsvData(HttpPostedFileBase file, int vendorId)
{
var listCsvImport = new List<CsvImport>();
try
{
using (var reader = new StreamReader(file.InputStream))
using (var csvReader = new CsvHelper.CsvReader(reader))
{
int count = 0;
while (csvReader.Read())
{
...<snip>...
listCsvImport.Add(record);
}
_db.CsvImports.AddRange(listCsvImport);
_db.SaveChanges();
}
...<snip>...
}
catch (CsvBadDataException ex)
{
log.Error("Invalid data in the CSV file, terminating process...");
throw;
}
catch (Exception ex)
{
log.Error("Csv import failed, no data was saved.", ex);
throw;
}
}
thanks