Note that there are some explanatory texts on larger screens.

plurals
  1. POGetOccurrence always throws exception
    text
    copied!<p>I have been trying to get appointments from outlook via the Outlook interop classes. Specifically those that are reoccurring appointments. I have tried using both v12 and v14 of the interop libraries with the same results. The following code always results in the same exception for me.</p> <p>Code:</p> <pre><code>Dim pattern As Outlook.RecurrencePattern = appt.GetRecurrencePattern() Dim recur As Microsoft.Office.Interop.Outlook.AppointmentItem = Nothing recur = rp.GetOccurrence(Now()) </code></pre> <p>Exception:</p> <blockquote> <p>You changed one of the recurrences of this item, and this instance no longer exists. Close any open items and try again.</p> </blockquote> <p>Note: I have used different values for the parameter to GetOccurrence, I am only using "now()" to simplify the code/problem. So I don't believe the problem lies in using Now(). I tried DateTime.Parse("8/28/2012") or DateTime.Parse("8/28/2012 5:00pm") with the name exception being thrown.</p> <p>I have looked at samples from here: <a href="https://stackoverflow.com/questions/90899/net-get-all-outlook-calendar-items/92184" title="Question 1">Question 1</a>, <a href="https://stackoverflow.com/questions/8043633/outlook-filter-items-get-all-recurring-appointments-in-a-week-range">Question 2</a>. Neither seem to have the same problem. I have tried every permutation of closing objects, releasing them, and nulling (nothing) them out. (e.g. <a href="http://jynxeddevelopment.blogspot.com/" rel="nofollow noreferrer">Microsoft Office Interop - Tricks and Traps</a>). I coppied and pasted examples directly from MSDN (ex: <a href="http://msdn.microsoft.com/en-us/library/office/ff184586.aspx" rel="nofollow noreferrer">MDSN</a>) with the same results. I am totally out of ideas! </p> <p>I am running on Windows Server 2008 R2 64bit OS, Using Visual Studio 2010, .NET 4.0, with Outlook 2007.</p> <p>Here is a more complete code example which always throws the exception for me:</p> <pre><code> Public Sub TestOutlook() Dim oApp As Outlook.Application = Nothing Dim mapiNamespace As Outlook.[NameSpace] = Nothing Dim calFolder As Outlook.MAPIFolder = Nothing Dim calItems As Outlook.Items = Nothing oApp = New Outlook.Application() mapiNamespace = oApp.GetNamespace("MAPI") calFolder = mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) calItems = calFolder.Items calItems.IncludeRecurrences = True For itemIndex As Integer = 1 To calItems.Count Dim item As Outlook.AppointmentItem = Nothing item = calFolder.Items.Item(itemIndex) If item.IsRecurring Then Dim rp As Outlook.RecurrencePattern = Nothing rp = item.GetRecurrencePattern() item.Close(Outlook.OlInspectorClose.olDiscard) CleanUpComObject(item) item = Nothing GC.Collect() Try rp.GetOccurrence(Now) Catch ex As System.Exception Debug.WriteLine("Ex with GetOccurrence: " &amp; ex.Message) End Try End If If item IsNot Nothing Then item.Close(Outlook.OlInspectorClose.olDiscard) CleanUpComObject(item) item = Nothing GC.Collect() Next CleanUpComObject(calItems) CleanUpComObject(calFolder) CleanUpComObject(mapiNamespace) oApp.Quit() CleanUpComObject(oApp) GC.Collect() End Sub Private Sub CleanUpComObject(obj As Object) Try If obj IsNot Nothing AndAlso System.Runtime.InteropServices.Marshal.IsComObject(obj) Then System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj) obj = Nothing End If Catch ex As System.Exception Debug.WriteLine("Exception in Clean up: " &amp; ex.Message) End Try End Sub </code></pre> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload