(mi.UserProperties.Find), , , mi.UserProperties; . MailItem.
Marshal.ReleaseComObject. UserProperty up UserProperty up.
Also, do not use foreachwith Outlook collections - this loop contains a link to all items until the loop completes. Use a loop forand free elements explicitly at each step of the loop immediately after you finish with this element
Selection selectedItems = Globals.ThisAddIn.Application.ActiveExplorer().Selection;
for (int i = 1; i <= selectedItems .Count; i++)
{
object selection= selectedItems[i];
MailItem mi = selection as MailItem;
if (mi != null)
{
UserProperties props = mi.UserProperties;
UserProperty up = props .Find("MyProp");
if (up != null)
{
...
Marshal.ReleaseComObject(up);
};
Marshal.ReleaseComObject(props);
Marshal.ReleaseComObject(mi);
};
Marshal.ReleaseComObject(selection);
};
source
share