I am receiving the above listed error during a series of property
assignments during the close event of a contact item in a VSTO SE COM
Add In.
The premise is very simple - the contact is opened and a number of
property values are set programmatically from an Access database.
Notably the entire content of the Body is changed to what is in the
database, the contact is saved and displayed. No problems at all in
opening the contact.
On the close event, several properties are again set and the content
of the Body is parsed by a function that strips our certain unwanted
substrings, and then the Body is set to the parsed value. The contact
is saved and closes.
The problem is the following (full description) error occurs after 2
or 3 contacts are opened and then closed.
A first chance exception of type 'System.AccessViolationException'
occurred in KWCongress2007_VSTO.DLL
System.Collections.ListDictionaryInternal
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
Microsoft.Office.Interop.Outlook
at Microsoft.Office.Interop.Outlook._ContactItem.set_Body(String
Body)
I have checked the code exhaustively, am using Option Strict with
every compile condition to throw a warning, and I am not getting any
warnings and the project compiles without hesitation. I've checked for
memory leaks using PerfMon and did not see any evidence of thread
stacks leaking, unmanaged memory leaking or memory in the managed
heaps building up.
The line of code that consistently causes the error and Outlook to
crash is:
oContact.Body = ParseMemberBody(sBody)
Where oContact is a strongly typed ContactItem, sBody is a strongly
typed String and ParseMemberBody is a private function that simply
iterates the sBody string and removes the unwanted substrings before
the value is set to the Body and the item is saved. I know it's not
this private function since I can't even use a simple string like
"Test body value".
I have tried releasing the item, calling GC.Collect() and getting the
item back using the EntryID - all of which works just great - but the
error still occurs.
I know it's the line referenced because I can rem it out and open and
close contacts from now to whenever without a problem. Put that line
back in and a crash is assured within a couple of open/close cycles.
I've lost two solid days on this and can not find any specific
reference to the issue. There are tons of unanswered questions about
the same error message but none about Outlook contacts and noen with
clear solutions.
Help, please!


|