Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In my Outlook Addin I subscribed to AttachmentRemove and AttachmentAdd of MailItem .

The Add Event fires while the Remove event is not fired in Outlook 2016. Outlook 2013 Both works. Both events are subscribed and unsubscribed the same time and the same way. I'm pretty sure no object is collected that would prevent raising the event.

edit (Version info)

Office Versions:

  • Microsoft Outlook 2016 MSO (16.0.13801.20240) 32-bit 2102 (Build 13801.20294 Click-to-Run)
  • Microsoft Outlook 2016 (16.0.5113.1000) MSO (13.0.5122.1000) 32-Bit
  • Both systems where office is installed are 64bit systems.

    edit (code snipped)

    public CommonItemInternal(object item)
        if (item == null)
            return;
        this.UniqueId = GetUniqueId(item);
        commonItemLookup.Add(this.UniqueId, this);
        this.Item = item;
        if (this.Item is MailItem)
            var mailItem = this.Item as MailItem;
            mailItem.PropertyChange += this.COM_CommonItemInternal_PropertyChange;
            mailItem.AttachmentRemove += this.COM_mailItem_AttachmentRemove; // <-- Does not get called
            mailItem.AttachmentAdd += this.COM_mailItem_AttachmentAdd; // <-- Get called
                    What is the actual code where you subscribe to events? How objects are declared in the code?
    – Eugene Astafiev
                    Mar 11, 2021 at 15:02
    

    First of all, make sure the source object is declared at the global scope the garbage collector doesn't swipe it out from the heap. Second, try to save the item. The Outlook object model may not react on UI changes until you switch the cursor to another field or save the item. Third, it is not clear what code is used for handling the AttachmentRemove event. I'd suggest posting all the code or just the minimum reproducible sample code.

    I wrap the MailItem in an Wrapper. That is keeped alive over the complete time the mailitem is used. I'm certain the object is not collected, since both add and remove are subscribed to in the same place. And Add works after I tested that remove does not. I try to create a minimal sample. This could take some time. – lokimidgard Mar 18, 2021 at 9:34 I tried to save the object after removing the attachment. This triggered the event as you suggested. It get also triggered if I use the context menu to remove the attachment (without extra calling save). Removing the attmchemt by marking it and press delete key will not trigger the event. – lokimidgard Mar 18, 2021 at 9:37

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.