title: Microsoft.Office.Interop.Excel Error with Windows Service
body: <p>I'm creating a windows service that will create excel sheets, I've used Microsoft.Office.Interop.Excel but got this Exception 
          <code>Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE</code>
  I've attached a photo here</p>
  
  <p><a href="http://i.stack.imgur.com/X4tKz.png" rel="nofollow">Exception photo attached</a></p>
  
  <pre><code>public void insertIntoSheet(string Name, DataTable dt)
  {
      Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
  
      if (xlApp == null)
      {
          //MessageBox.Show("Excel is not properly installed!!");
          return;
      }
      Excel.Workbook xlWorkBook;
      Excel.Worksheet xlWorkSheet;
      object misValue = System.Reflection.Missing.Value;
  
      xlWorkBook = xlApp.Workbooks.Add(misValue);
      xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
      for (int i = 1, j = 0; j &lt; dt.Rows.Count; i++, j++)
      {
          xlWorkSheet.Cells[i, 1] = dt.Rows[j][0].ToString();
          xlWorkSheet.Cells[i, 2] = dt.Rows[j][1].ToString();
          xlWorkSheet.Cells[i, 3] = dt.Rows[j][2].ToString();
          xlWorkSheet.Cells[i, 4] = dt.Rows[j][3].ToString();
          xlWorkSheet.Cells[i, 5] = dt.Rows[j][4].ToString();
          xlWorkSheet.Cells[i, 6] = dt.Rows[j][5].ToString();
      }
      //xlWorkSheet.Cells[1, 1] = "Sheet 1 content";
  
      xlWorkBook.SaveAs(String.Format("d:\\{0}.xls", Name), Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
      xlWorkBook.Close(true, misValue, misValue);
      xlApp.Quit();
  
      releaseObject(xlWorkSheet);
      releaseObject(xlWorkBook);
      releaseObject(xlApp);
      Class_Library.WriteErrorLog("Inserting the sheet method finished");
      //MessageBox.Show("Excel file created , you can find the file d:\\csharp-Excel.xls");
  }
  
  private void releaseObject(object obj)
  {
      try
      {
          System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
          obj = null;
      }
      catch (Exception ex)
      {
          obj = null;
          Class_Library.WriteErrorLog(ex.Message);
          //MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
      }
      finally
      {
          GC.Collect();
      }
  }
  </code></pre>
  
  <p>NOTES: I've used the same code as a test in windows application and it worked as expected.
  I've tried to write <code>Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();</code> and also tried to use the Name Excel only like <code>Excel.Application xlApp = new Excel.Application();</code></p>