Word appears to be getting confused

D

David Thielen

I see this error in the following code:
foreach (InlineShape item in
range.InlineShapes)
{
try
{
if ((item.Range.End <=
startSearch) || (endSearch <= item.Range.Start))
continue;

// chart (with tag)?
if (item.HasChart ==
MsoTriState.msoTrue)
{
// fast check
if
(string.IsNullOrEmpty(item.AlternativeText) ||

((!item.AlternativeText.StartsWith("<wr:")) &&
(!item.AlternativeText.StartsWith("</wr:"))))

continue;

string
xmlChart = item.Range.WordOpenXML;

On the call to WordOpenXML I get a COMException of:
- $exception {"The object is not valid."}
System.Exception {System.Runtime.InteropServices.COMException}

What's really screwy is in the debugger I can then do a Quickwatch on
"item.Range.WordOpenXML" and I get the string - no exception.

Then when I say continue I get:
System.AccessViolationException occurred
Message="Attempted to read or write protected memory. This is often
an indication that other memory is corrupt."
Source="Microsoft.Office.Interop.Word"
StackTrace:
at Microsoft.Office.Interop.Word.Range.get_ShapeRange()
at
AutoTag2010.net.windward.autotag.word.WordTagHandler.FindAllTags(Selection
selOn, Boolean justFirst, Int32 startSearch, Int32 endSearch) in
C:\src\version9\AutoTag\AutoTag2010\net\windward\autotag\word\WordTagHandler.cs:line
677
InnerException:

And Word is basically hosed - I need to exit it.

Any idea why?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
D

David Thielen

Found & fixed - the call to WordOpenXML was triggering the selection
change event (no idea why) which my handler then recursively called
back in to this code.

Calling WordOpenXML recursively is very very bad!!!

- dave


I see this error in the following code:
foreach (InlineShape item in
range.InlineShapes)
{
try
{
if ((item.Range.End <=
startSearch) || (endSearch <= item.Range.Start))
continue;

// chart (with tag)?
if (item.HasChart ==
MsoTriState.msoTrue)
{
// fast check
if
(string.IsNullOrEmpty(item.AlternativeText) ||

((!item.AlternativeText.StartsWith("<wr:")) &&
(!item.AlternativeText.StartsWith("</wr:"))))

continue;

string
xmlChart = item.Range.WordOpenXML;

On the call to WordOpenXML I get a COMException of:
- $exception {"The object is not valid."}
System.Exception {System.Runtime.InteropServices.COMException}

What's really screwy is in the debugger I can then do a Quickwatch on
"item.Range.WordOpenXML" and I get the string - no exception.

Then when I say continue I get:
System.AccessViolationException occurred
Message="Attempted to read or write protected memory. This is often
an indication that other memory is corrupt."
Source="Microsoft.Office.Interop.Word"
StackTrace:
at Microsoft.Office.Interop.Word.Range.get_ShapeRange()
at
AutoTag2010.net.windward.autotag.word.WordTagHandler.FindAllTags(Selection
selOn, Boolean justFirst, Int32 startSearch, Int32 endSearch) in
C:\src\version9\AutoTag\AutoTag2010\net\windward\autotag\word\WordTagHandler.cs:line
677
InnerException:

And Word is basically hosed - I need to exit it.

Any idea why?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

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