Properties removed from PropertyAccessor sometimes "resurfacing"?

Add-in Express™ Support Service
That's what is more important than anything else

Properties removed from PropertyAccessor sometimes "resurfacing"?
Issue with Sent Items - Outlook 365 - Cached Exchange Mode? 
Andrei Smolin


Add-in Express team


Posts: 16670
Joined: 2006-05-11
A great point it is!

I think the only way to bypass such issues is to get, cache, pass and release COM objects in an order; the order being obviously the matter of personal taste, experience and views.

We suggest that instead of holding a COM object for any significant time, you store the information required to recreate the COM object. This corresponds to the next rule that we actively use: Release COM objects as soon as you're done with them. We've met a rule further beautifying this one: Release COM objects in the order reverse to the order of their creation.

One more rule refers to passing a COM object: the caller is responsible for the COM object passed to a callee; the callee should not release COM objects received. This only works with Add-in Express components. Without them, if you connect to an Office event via

C#: {some object such as ExcelApp or Outlook.Explorer}.{event name} += {event handler}
VB.NET: AddHandler {some object such as ExcelApp or Outlook.Explorer}.{event name}, AddressOf {event handler} 


you are responsible for releasing a COM object(s) that the event handler receives! Not releasing such a COM object(s) can cause an issue as well.

Also, we suggest that you add an element of order to the way you release a COM object:

C#: Marshal.ReleaseComObject(someObject); someObject = null;
VB.NET: Marshal.ReleaseComObject(someObject): someObject = Nothing


Strictly speaking, nullifying the variable above is not required and it might be omitted. But there's a possibility that later on you'll modify the code so that someObject is used after it is released. If the nullifying statement is present, you'll get an acquaintance - NullReferenceException. Otherwise, you'll me a hostile stranger - InvalidComObject shouting at you that "COM object that has been separated from its underlying RCW cannot be used". Well, sort of personal, too.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Oct, 2019 06:04:50 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
Hello Andrei,

This is exactly what I ended up doing and my addin as a result is now a lot more robust.

The only issue that still persists is effectively the same as the one described here:
https://www.add-in-express.com/forum/read.php?TID=15024

As Bert Sinnema already discovered, nothing you can do will stop the behaviour from happening. He had the problem with Outlook 2016, and I can now confirm that the same problem exists in Outlook 2013

As far as I can tell the behaviour ONLY manifests itself when adding a UserProperty to a mailitem, and even more specifically, it ONLY happens on items in the Sent Items

I tried the suggestion made in the thread in many different ways. I even went as far as taking an entry ID, kicking off a timer waiting 10 seconds and in the timer setting the User Property. No joy; still the same problem.

But what *does* work, as clunky as it may seem is this:

- Create a Copy object: oMailItemCopy = oMailItem.Copy
- Delete the Mail item: oMailItem.Delete
- Delete the most recent item in the Deleted Items folder (as described in many threads here, works perfectly)
- ReleaseComObject on oMailItem

The user won't be any the wiser, but now you no longer get that message.
Posted 11 Oct, 2019 15:28:29 Top
Andrei Smolin


Add-in Express team


Posts: 16670
Joined: 2006-05-11
Hello Pino,

Pino Carafa writes:
kicking off a timer


A System.Windows.Forms.Timer?

Are all other add-ins turned off? Is the Reading pane turned off? What is the error message? What is the caption of the error message window?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Oct, 2019 00:57:24 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
It's not an error message, Andrei. The only symptom showing me that anything is wrong is when I open the message, and at the top of the message there's a little line that states "This is the most recent version, but you made changes to another copy. Click here to see the other versions."

The (pseudo) code in the timer "tick" boils down to this:

Use some EntryID to GetItemFromID into oMailItem

oProps = oMailItem.UserProperties
oProp = oProps.Find("<someproperty>")
If oProp Is Nothing Then
oProp = oProps.Add("<someproperty>")
End IF
Marshal.ReleaseComObject(oProp)
Marshal.ReleaseComObject(oProps)

oMailItem.Save()
Marshal.ReleaseComObject(oMailItem)

(obviously there is some error handling and setting objects to Nothing in there too, but I've left that out here)

If I leave out the code between Setting the oProps variable and Releasing it, the issue doesn't happen.

What I also noticed is that if I allow the Timer to "tick" more than once for a particlar EntryID then even though it has ticked before and I set the Property on the previous "tick", the .Find returns Nothing on the next Tick. Which makes sense in the context of my GetItemFromID retrieving a "different copy" from the one I updated earlier.

To recap, and answering your questions:
- I haven't yet tried it will all other Add-ins turned off. Will do that now and I'll let you know what I find.
- The Reading Pane is off
- It's not an error message but a notification at the top of the Inspector window
Posted 14 Oct, 2019 03:17:31 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
Alas, with all other Add-ins disabled the same thing still happens :(
Posted 14 Oct, 2019 03:33:36 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
Please note that this happens in the same scenario as that described by Bert Sinnema in his issue. Exchange is online (Outlook 365) and Outlook is running with Cached Exchange Mode switched on. The only difference seems to be that Bert's client is Outlook 2016 while I'm reproducing this in Outlook 2013
Posted 14 Oct, 2019 04:31:50 Top
Andrei Smolin


Add-in Express team


Posts: 16670
Joined: 2006-05-11
http://temp.add-in-express.com/support/MyAddin136-PinoCarafa.zip

Can you reproduce the issue with this add-in?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Oct, 2019 04:49:59 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
Hello Andrei,

Yes. The same thing happens with that add-in.
Posted 14 Oct, 2019 05:12:38 Top
Andrei Smolin


Add-in Express team


Posts: 16670
Joined: 2006-05-11
Hello Pino,

Could you please send me a video showing how do you test the project?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Oct, 2019 05:26:14 Top
Pino Carafa




Posts: 81
Joined: 2016-09-28
Sure.... How can I do that? I don't seem to have the option to attach files here?
Posted 14 Oct, 2019 05:34:01 Top