all groups > dotnet interop > august 2006 >
You're in the

dotnet interop

group:

AccessViolationException openning Excel WorkBook



AccessViolationException openning Excel WorkBook hSiplu
8/9/2006 1:41:18 AM
dotnet interop:
hi,
can anyone tell me why the folowing statement throws an
AccessViolationException ?

my developing pc is WinXP Pro with MSOffice2003 and the release version
runs on Windows 2000 Pro with Office2000 while my client can't change
his configuration. The Debug version does not throw the exception but
the release version throws.

wrkBook = appClass.Workbooks.Open( ((myItem)fileList[i]).filepath,
2,
false,
missing,
missing,
missing,
true,
XlPlatform.xlWindows,
missing,
missing,
true,
missing,
false,
false,
XlCorruptLoad.xlNormalLoad
);

============================================================
here is my full method body
============================================================
public void converXLS2CSV(ToolStripProgressBar tpBar,
ToolStripStatusLabel tsLabel, ToolStripStatusLabel tsLabel2)
{
// Marge all the stored Excel files into one Excel
// file so that query can be executed very easily.
// Necessary variable dicleration;

Blog(4);log("setting status text");
tsLabel.Text = "Starting ...";
Blog(5);log("creating application class");
appClass = new ApplicationClass();
Blog(6);log("initializing progressbar");
initializeProgressbar(tpBar, fileList.Count,
ProgressBarStyle.Continuous);
Blog(7);log("entering for loop");
for(int i = 0 ; i< fileList.Count; i++)
{
Blog(8);log("loop count:" + i.ToString());
if (((myItem)fileList[i]).check.Checked)
{
Blog(9);log("fileList[" + i.ToString() + "] is
checked");
Blog(10);log("Showing status information");
// showing status information
tsLabel.Text = "Converting ...";
Blog(11);log("setting tsLabel2.Text");
tsLabel2.Text = ((myItem)fileList[i]).check.Text;
Blog(12);log("refreshing the label parent");
tsLabel2.GetCurrentParent().Refresh();

Blog(13);log("getting special directories");
// Creating the converted name of the file
string convertedCSV = SpecialDirectories.Temp +
@"\" + Path.GetFileNameWithoutExtension(((myItem)fileList[i]).filepath)
+ ".csv";
Blog(14);

//------------------------------------------------------------------------------
// here throws the AccessViolationException

//------------------------------------------------------------------------------
log("openning workbook:" +
((myItem)fileList[i]).filepath.ToString());
// Openning the workbook
wrkBook =
appClass.Workbooks.Open(((myItem)fileList[i]).filepath, 2, false,
missing,
missing, missing, true, XlPlatform.xlWindows,
missing, missing, true, missing,
false, false, XlCorruptLoad.xlNormalLoad);
bug("Opening file :\n" +
((myItem)fileList[i]).filepath+"\nDeleting file:\n"+convertedCSV);

Blog(15);log("deleting the existing file");
// Delete the file if it exists
if (File.Exists(convertedCSV))
{
File.Delete(convertedCSV);
}
Blog(16);log("Saving the workbook");
// Saving the workbook as csv file
wrkBook.SaveAs(convertedCSV,
XlFileFormat.xlCSVWindows, false, false,
missing, false, XlSaveAsAccessMode.xlNoChange,
XlSaveConflictResolution.xlOtherSessionChanges,
false, missing, missing, false);
Blog(17);log("Closing the workbook");
// Closing the workbook
wrkBook.Close(false,
((myItem)fileList[i]).filepath, missing);

// Changing the stored file path
//((myItem)fileList[i]).filepath = convertedCSV;
}
Blog(17);log("Performing animation");
// Performing animation
tpBar.PerformStep();
}
Blog(18);log("Resetting the progressbar to it's initial
position");
// Resetting the progressbar to it's initial position
resetProgressbar(tpBar);
Blog(19);log("qUITING APPLICATION");
appClass.Quit();
}
By the way,
I did not catch any exception becoz first i have to make a clear line
of execution then I shall appy all the exception. That's how I code.
please help me !
Re: AccessViolationException openning Excel WorkBook Cindy M.
8/10/2006 12:00:00 AM
Hi HSiplu,

[quoted text, click to view]
You are aware that the 2000 version probably has a different method
signature for the Open method than 2003? Quite likely, you're passing too
many parameters.

It's very... unwise to develop for an older version with newer type
libraries. If you're going to develop solutions that should run with
Office 2000 then you need to use that on your development machine.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Re: AccessViolationException openning Excel WorkBook hSiplu
8/10/2006 4:30:54 AM
hi,
After developing I have discovered that it has to be run on a machine
with Office2000.
And how I can I change my Office2003 to Office2000 ?
Re: AccessViolationException openning Excel WorkBook Cindy M.
8/11/2006 12:00:00 AM
Hi HSiplu,

[quoted text, click to view]
You can't, at least, not directly.

You need to obtain and install Office 2000. Over E-bay, perhaps...

If you'd be willing to use VB.NET with Option Strict OFF, you might be
able to get away with what you're trying, assuming you haven't included
any post-Excel 2000 functionality in your solution. VB.NET supports
named, optional parameters so you wouldn't run into this particular
problem.

The other possible solution is to use late-binding (Reflection,
GetType, InvokeMethod, that kind of thing). The version IAs wouldn't be
an issue, either.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
AddThis Social Bookmark Button