I'm working on an Outlook Add-In (plugin) and I'm basically working with Outlook appointment items (Outlook.AppointmentItem
).
Each time someone create, save or update an occurrence of a periodic appointment item, i need to get the main AppointmentItem
(the parent) and add or update an UserProperty
.
Until here, it's more or less working. That means i get the parent and i can manipulate his UserProperties
but it doesn't work every time.
If the periodic appointment has 5 occurrences and for each references i update something, I'm expecting to modify the UserProperties
of the parent 5 times. But that doesn't work and sometimes the parent his old "state".
Technically, in the Item_Write
I get the parent and change his UserProperties
. And just before the last bracket of the Item_Write
i check the UserProperties of the parent and they contain what I'm expecting. But in the "Close" method who is called just after the Item_Write
when i check if the parent still contain the expected UserProperties
I see that they haven't been updated and they still are in the same state that before.
After some research, i saw a lot of people (even the Msdn) saying that i should use Marshal.ReleaseComObject()
. I tried that and now I'm releasing the parent (and other COM
object) every time i call them. Maybe I'm not using it well and because of that, it's still doesn't work.
The problem seems to appear between the Item_Write
and the Close
. After leaving Item_Write
the UserProperties
are okay, but when i enter the Close
they are not anymore.
Does anyone ever have any similar problem?
Should i use Marshal.FinalReleaseComObject()
on the parent just before the end of Item_Write
?
I you think it's better or it will be easier to understand what's going on by looking at some part of my code, just ask.
This sounds like it is most definitely related to not properly releasing objects. Read the Remarks section in the documentation for the AppointmentItem.GetRecurrencePattern method as it describes your situation perfectly: https://msdn.microsoft.com/en-us/library/office/ff868441.aspx.