title: C# and Excel interop
body: <p>One of my users is having an issue when trying to open an Excel file through my C# app.</p>
  
  <p>Everything works ok when I run it from my machine and it works for other users.  I am no Excel interop expert so hopefully you guys can help me out.</p>
  
  <p>Here is how it is set up:</p>
  
  <p>I added a reference to my app to Microsoft.Office.Interop.Excel.dll, version 10.0.4504.0 (which I believe is Excel 2002).  On my machine I have installed Excel 2007.
  In my code I try to open a worksheet like so:</p>
  
  <pre><code>using Microsoft.Office.Interop
  ...
  Microsoft.Office.Interop.Excel.ApplicationClass _excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
  Microsoft.Office.Interop.Excel.Workbook excelWorkbook = _excelApp.Workbooks.Open(workbookPath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", false, false, 0, true, false, false);
  Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;
  Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(1);
  </code></pre>
  
  <p>I logged the users version as Excel 9.0 (which is 2000).  The error that the user gets is:</p>
  
  <pre><code>Exception='System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
     at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
  </code></pre>
  
  <p>It looks like the workbook cannot be opened.  The file was confirmed to exist and was just loose on the user's PC at C:.  I thought by using the PIA I wouldn't have to worry about Excel version issues.  I know there are other users using Excel 2000, and it works on my development machine.</p>
  
  <p>Any ideas?  Maybe my calls to open the Excel file should be changed?  The unfortunate thing is that I am unable to reproduce it.</p>