hello everyone.
i'm trying to open an excel workbook using c#.
this is the code:
using Excel;
Excel.Application excelApp = new Excel.ApplicationClass();
string workbookPath = "c:/SomeWorkBook.xls";
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
when i run the program on the same pc that has the c# environment it
runs without problem, but when i try to run it on another pc i have the
following error:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
this exception is thrown when i try to open the workbook.
i've tried on several pc with different version of Excel (2003, 2000), but the results are the same.
any suggest
thanx

attempt to read or write protected memory
Jamie Thomson
as far as i know no, but i will check more deeply.
Chien Lim
I found your posts because I'm having the same problem.
Found a likely solution at http://vbforums.com/showthread.php t=433311.
Looks like you have to remove all references to Excel objects when using late binding.
Hope that helps.
-jpr
Jessie J
// Defined on the class
private global::System.Object missing = global::System.Type.Missing;
...
...Open(workbookPath, 0, false, 5, missing, missing, false, ...
Guruprasad H R
unfortunatly the result doesn't change.....
anyway thanks
Neorga
Praveen Dayanithi
yes
no, excel is closed. i open excel without problem. i have the exception when i try to open the file.
no.....
thanx
interpro1
kblackwell
envi_ria
Some random thoughts:
Good luck.
pappascd
Microsoft Excel 10.0
pino69
yes, they are located in the same directory of the .exe file
following the list of these files:
Interop.Excel.dll
Interop.Microsoft.Office.Core.dll
Interop.VBIDE.dll
djshades2004
In case some people are still facing this problem, I have one possible cause for such errors. As it happens, a lot of com dlls (pia's) are not downward compatible. In case you are developing against, say a Word XP version and have added these references to your .NET project, then this error message may occur when you deploy your application in an environment that uses WORD 2000 or so. It will not always happen, in my case it occurred when I wanted to pass a String to the COM object, for instance a file name to open a word document through automation.
to solve this problem, one needs to develop an automation application using the oldest automation library that is needed. So basically you have to ensure upwards compatibility. In my case, where I needed to deploy against WORD 2000, I had to create the pias myself using tlbimp.exe (using the command line):
tlbimp.exe msword9.olb /keyfile:<mykeyfilename.snk> /out: Microsoft.Office.Interop.Word2000.dll
the file msword9.olb can be found in office2000, so you would need to get that file from a WORD 2000 installation disk or otherwise. In the command, I have chosen to use the same naming convention as is done in WORD XP (Microsoft.Office.Interop.... so that the c# code can be easily adjusted. Last, the type libraries need to be signed or else Visual Studio will not accept them.
In this case, I can now add a reference Microsoft.Office.Interop.Word2000 to my project and adjust the appropriate com calls.
This solved my problems with memory.
see for info:
http://www.devcity.net/PrintArticle.aspx ArticleID=163
http://support.microsoft.com/kb/313666