Error: Attempted to read or write protected memory

A

Amrish

Hi All,

I have a complex report which is generated through word automation. I use
Visual Studio 2005, Word 2003 DLL's and i do the programming in C#.

I perform a sequence of operations and track every operation with a log. And
the application was working fine on almost all the client machines but one
machine threw an exception which was caught in the Logger.

{Interop.Word} : Attempted to read or write protected memory. This is often
an indication that other memory is corrupt.
at Word.Selection.ClearFormatting()

This sequence comes after I insert a table at one point of time and use the
ClearFormatting() method to clear the contents Formatting. But the irony is
that during development, i had this exception thrown when i was inserting 2
Logo's in the page header. Somehow the issue was not recurring later on. In
some other post where the users were getting some similar exception,
suggestion was given to change the Tool-->Security-->Macro settings. It was
not of any help here.

Is this issue is due to some other reason? or is it because of the code. The
DLL's too gets installed on the Clients machine along with the application.
 
C

Cindy M.

Hi =?Utf-8?B?QW1yaXNo?=,

My suspicion is that this corresponds to the end-user message about "complex
formatting" that comes up when Word's scratch files overflow. If you save the
document and/or clear the Undo buffer just before this line, does that make any
difference?

The other angle to look at is whether this may be a problem with using Selection
instead of a Range. Possibly, the Selection is invalid for this command. If you
want to clear the memory in a particular table, perhaps something more along
these lines:

Word.Range rng = Selection.Tables[1].Range;
rng.ClearFormatting();
I have a complex report which is generated through word automation. I use
Visual Studio 2005, Word 2003 DLL's and i do the programming in C#.

I perform a sequence of operations and track every operation with a log. And
the application was working fine on almost all the client machines but one
machine threw an exception which was caught in the Logger.

{Interop.Word} : Attempted to read or write protected memory. This is often
an indication that other memory is corrupt.
at Word.Selection.ClearFormatting()

This sequence comes after I insert a table at one point of time and use the
ClearFormatting() method to clear the contents Formatting. But the irony is
that during development, i had this exception thrown when i was inserting 2
Logo's in the page header. Somehow the issue was not recurring later on. In
some other post where the users were getting some similar exception,
suggestion was given to change the Tool-->Security-->Macro settings. It was
not of any help here.

Is this issue is due to some other reason? or is it because of the code. The
DLL's too gets installed on the Clients machine along with the application.

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top