Avatar of Iranor
IranorFlag for Canada

asked on 

"Attempted to read or write protected memory" while opening word document

Hi,
I have a small c# application that opens a word document and get all the content from it, then loads it in the clipboard. It works perfectly on my development machine, however, when I move it to the end-user computer at my job, this message shows up:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Stack trace:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.Office.Interop.Word.Documents.Open(..)

Below is my code. At first I thought it would be document's permission, however, I have full permission to both documents and it's in the root of my C drive.

I doubt it is related to my word version... I use Microsoft Word 11.0 Object Library, and I have word 2003 on my development machine, while word 2002 is on the end-user machine..

I included all the required dll in my application's main directory, no change. The same framework is on both machine.

Any idea on what's going on?
Object PhonebookDirectory = @"C:\mydoc.doc";
Word.ApplicationClass wordApp = new Word.ApplicationClass();
Word.Document mDoc = wordApp.Documents.Open(ref PhonebookDirectory, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
mDoc.ActiveWindow.Selection.WholeStory();
mDoc.ActiveWindow.Selection.Copy();
 
IDataObject data = Clipboard.GetDataObject();
String sCache = data.GetData(DataFormats.Text).ToString();

Open in new window

.NET ProgrammingC#

Avatar of undefined
Last Comment
Iranor
ASKER CERTIFIED SOLUTION
Avatar of ShazbotOK
ShazbotOK
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Iranor
Iranor
Flag of Canada image

ASKER

Ahh I see... Only problem is that, I can't pick Word 10.0 in visual studio 2005...

Is there any place I can download it and replace Word 11.0?
Avatar of Iranor
Iranor
Flag of Canada image

ASKER

Finally I downloaded office xp pia and added as a reference and it worked, thanks ^^
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo