How to remove Exceptions from recurring meeting in Outlook 2013 C# COM addin RRS feed

  • Question

  • Hi,

    I'm using VSTO 2010 to create an Outlook addin in C#, for Outlook 2007 and 2010. Now I'm adding support for Outlook 2013. In my tests I'm connecting to an Exchange Online mailbox from Outlook 2013 (32bit version 15.0.4667.1002).

    How can I remove all exceptions from a recurring meeting (with attendees and invitations sent) from my addin code?

    In Outlook 2007 and Outlook 2010, I managed this by resetting the pattern end date:

    public void RemoveExceptions(Outlook.AppointmentItem item)
        Outlook.RecurrencePattern pattern = item.GetRecurrencePattern();
        pattern.PatternEndDate = pattern.PatternEndDate;

    However if I try this on Outlook 2013 the exceptions are not removed from meetings with invitations already sent.

    Initially it appears to be working (i.e. all occurrences are back on the original date and cancelled occurrences are visible again on the calendar), but after a few seconds to a few minutes the Outlook calendar reverts to showing the modifications and cancellations. This happens most of the time, but sometimes only the deleted occurrences are deleted again and rarely the exceptions appear to have been removed successfully. Could this behavior depend on how many modifications I applied in the modified occurrences?

    Removing the exceptions does still work the same as in Outlook 2007 and 2010 for recurring appointments without attendees and for recurring meetings where I didn't send the invitations yet.

    I would like to retain the behavior seen in Outlook 2007 and 2010 on Outlook 2013. Do you have any suggestions?

    Thanks very much in advance,


    P.S. looking at the attendees' calendars, I see they do get all exceptions removed permanently. Only the meeting organizer gets the exceptions back in his calendar.

    Thursday, November 20, 2014 5:35 PM

All replies

  • Hello Yorik,

    The ReccurencePattern class provides the Exceptions property which returns the Exceptions collection for a specified series of recurring appointments. You may check out the Deleted property of the Exception class and, if it is alive, you may get an associated AppointmentItem.

    When you work with recurring appointment items, you should release any prior references, obtain new references to the recurring appointment item before you access or modify the item, and release these references as soon as you are finished and have saved the changes. This practice applies to the recurring AppointmentItem object, and any Exception or RecurrencePattern object. 

    Make sure that you release all references in the code. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it.  Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about that in the Systematically Releasing Objects article.

    Thursday, November 20, 2014 5:52 PM
  • Hi Eugene, thanks for your reply.

    I am using Marshal.ReleaseComObject for the RecurrencePattern and any other references to children of the master appointment object. Now for the appointment item itself, the addin creates a COM reference when the user opens the inspector window for this appointment. This reference is used to attach write and send event handlers.

    I'm trying to remove the exceptions from the write event handler attached to the master appointment. The reference to the master appointment is not released until the inspector window closes (and the addin also stores some information in a user property after the exceptions are removed). I'll try to release and recreate the reference sooner and I'll post my results.

    Please let me know if you have further comments.


    Thursday, November 20, 2014 6:59 PM
  • I've modified my code to renew the reference to the recurring appointment before applying the change:

    public void RenewItem(ref Outlook.AppointmentItem item)
        IntPtr pointer = Marshal.GetIUnknownForObject(item);
        item = (Outlook.AppointmentItem)Marshal.GetUniqueObjectForIUnknown(pointer);

    Now I'm running this code fragment from the write event handler:

    public void AppointmentItem_Write(ref bool cancel)
        RenewItem(ref item);
        item = null;

    I still see the same behavior I described in my initial post. I've also tried removing the exceptions before the write event handler gets called, but this didn't improve the results.

    Is there a better way to get a new reference to the appointment item?

    • Edited by YorikG Friday, November 21, 2014 1:34 PM tried removing exceptions before write event
    Friday, November 21, 2014 1:06 PM
  • You can use the GetItemFromID method of the Namespace class.
    Friday, November 21, 2014 2:01 PM
  • Thanks again for the tip! Unfortunately it's not helping. Also I found this issue does occur also on Outlook 2010, but not on Outlook 2007.

    I think I'll avoid removing the exceptions from the add-in.

    Monday, November 24, 2014 11:53 AM