在Outlook中更新定期约会时,该对象不支持此方法

时间:2017-08-31 14:42:35

标签: c# outlook-addin comexception

我在使用Outlook的API更新定期约会时遇到问题。我一直收到一个COMException说明,

System.Runtime.InteropServices.COMException (0x90720009): The object does not support this method.
at Microsoft.Office.Interop.Outlook._AppointmentItem.set_Start(DateTime Start)
at Outlook_Calendar_Sync.CalendarItem.GetOutlookAppointment(AppointmentItem item) in D:\Documents\Visual Studio 2015\Projects\Outlook-Calendar-Sync\Outlook Calendar Sync\CalendarItem.cs:line 228

我已经验证它是一个实际的AppointmentItem接口但我仍然遇到此错误。任何帮助将不胜感激。以下是我尝试更新AppointmentItem的代码。

Log.Write( $"Updating recurring Outlook appointment, {ev.Subject}" );
                // Create the filter to find the event. This is done by either the subject and start date or the ID
                var filter = ( ev.Action.HasFlag( CalendarItemAction.GeneratedId ) )
                    ? ( "[Subject]='" + ev.Subject + "'" )
                    : "[ID] = '" + ev.ID + "'";

                var appointmentItems = m_folder.Items.Restrict( filter );
                foreach ( AppointmentItem appointmentItem in appointmentItems )
                {
                    if ( appointmentItem.RecurrenceState != OlRecurrenceState.olApptMaster )
                        continue;

                    appointmentItem.GetRecurrencePattern();
                    ev.GetOutlookAppointment( appointmentItem );
                    appointmentItem.Save();

                    ev.Action &= ~CalendarItemAction.GeneratedId;
                    ev.Action &= ~CalendarItemAction.OutlookUpdate;
                }

ev.GetOutlookAppointment( appointmentItem )中,我将内部存储类转换为Outlook AppointmentItem接口。

这是该方法的开始:

        public AppointmentItem GetOutlookAppointment( AppointmentItem item ) {
        try
        {
            item.Start = DateTime.Parse( Start );
            item.End = DateTime.Parse( End );

尝试更改item.Start DateTime时会抛出COMException。

0 个答案:

没有答案