End Google Ads 201810 - BS.net 01 --> I had this code working yesterday. Today I get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Here's the code. It errors on the oSheet.SaveAs line:


Microsoft.Office.Interop.Excel.Application oXL;
Microsoft.Office.Interop.Excel._Workbook oWB;
Microsoft.Office.Interop.Excel._Worksheet oSheet;

oXL = new Microsoft.Office.Interop.Excel.Application();
oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;

Reader = new StreamReader(ExportParams.sSourceFileName);

iRow = 0;
sSourceRow = Reader.ReadLine();

while (sSourceRow != null)
{
iRow++;
string[] aWords = sSourceRow.Split(',');

oSheet.Cells[iRow, 1] = aWords[0];
oSheet.Cells[iRow, 2] = aWords[1];
oSheet.Cells[iRow, 3] = aWords[2];

sSourceRow = Reader.ReadLine();
}

Reader.Close();

if (File.Exists(ExportParams.sResultFileName))
{
File.Delete(ExportParams.sResultFileName);
}

oSheet.SaveAs(ExportParams.sResultFileName,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

oXL.Quit();

Everything makes sense in someone's mind