title: Excel Object generates error after the application is published
body: <p>My VB.NET Windows forms application is writing data into excel file. It works without any error in development environment. The excel file gets created with data. </p>
  
  <p>But when the application is deployed/Published. It gives error : "Object reference not set to an instance of an object" at xlWorkBook.SaveAs</p>
  
  <p>Error is confusing. Is it a permission issue? Any help.</p>
  
  <p>Below is the code:</p>
  
  <pre><code>Dim xlApp As Excel.Application = New Excel.Application
  xlApp.SheetsInNewWorkbook = 1
  
  Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Add
  
   Dim xlWorkSheet As Excel.Worksheet = CType(xlWorkBook.Worksheets.Add(), Excel.Worksheet)
  
   xlWorkSheet.Name = "Sample1"
   xlWorkSheet.Cells(1, 1) = "TestData1"
   xlWorkSheet.Cells(1, 2) = "TestData2"
  
  xlApp.DisplayAlerts = False
  
  xlWorkBook.SaveAs(gExcelFileName, Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, _
                                     Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges)
  </code></pre>