Error "Cannot read one instance ..." when user adds/changes exception

Add-in Express™ Support Service
That's what is more important than anything else

Error "Cannot read one instance ..." when user adds/changes exception
User gets a runtime error in recurring meetings 
Mike O'Shaughnessy




Posts: 35
Joined: 2008-04-18
Hi,

I am writing a VSTO 2008 add-in for Outook 2007 using Add-In Express VSTO 2008 and VB .NET. I am consistently getting a run time error related to recurring appointments and exceptions. The message that is displayed is:


"Cannot read one instance of this recurring appointment. Close any open appointments and try again, or recreate the appointment."


Note that I have "Cached Exchance Mode" OFF (this is a requirement for our users).

To recreate the issue:

  • Create a new VB Outlook 2007 project in VS 2008
  • Add a new ADX module
  • In the ADXModule1 designer, add a new ribbon tab
  • In the properties for AdxRibbonTab1, click on controls and add an AdxRibbonGroup
  • Select AdxRibbonGroup1 and add a ADXRibbonButton
  • In the properties for AdxRibbonGroup1, change Ribbons to "OutlookMeetingRequestRead;OutlookMeetingRequestSend;OutlookAppointment"
  • Add my code to the RibbonButton1 OnClick Event (see below)
  • start debugging by pressing F5
  • When outlook starts, create a weekly recurring meeting
  • Open the first occurrence of the meeting, select "this occurrence", and update the body (creates the first exception)
  • Open the second occurence of the meeting, type text into the body and click save & close (creates the second exception)
  • open the first occurence of the meeting and click the AdxRibbonButton1. You will see 3 popups with recurring item and exception detains.
  • open the first occurence of the meeting again and you will start getting error popups. These errors will now happen whenever you try to open an occurence of the meeting and when you click RibbonButton1


Here is my code for the AdxRibbonButton1_OnClick sub:

    Private Sub AdxRibbonButton1_OnClick(ByVal sender As System.Object, ByVal control As AddinExpress.VSTO.IRibbonControl, ByVal pressed As System.Boolean) Handles AdxRibbonButton1.OnClick
        Dim inspector As Outlook.Inspector = Nothing
        Dim apptItem As Outlook.AppointmentItem = Nothing
        Dim exceptItem As Outlook.AppointmentItem = Nothing
        Dim recurPattern As Outlook.RecurrencePattern = Nothing
        Dim exceptCount As Integer = Nothing
        Dim index As Integer = 0

        Try
            ' get recurrence pattern of the inspector's current item
            inspector = Me.OutlookApp.ActiveInspector
            apptItem = inspector.CurrentItem
            recurPattern = apptItem.GetRecurrencePattern

            ' count of exception items
            exceptCount = recurPattern.Exceptions.Count

            ' display recurrence info
            MsgBox("Recurrence type[" + recurPattern.RecurrenceType.ToString + "] " _
                   + "Exception count[" + exceptCount.ToString + "] " _
                   + "]")


            If exceptCount > 0 Then
                ' loop through all exception items and display info for each one
                index = 1
                While index <= exceptCount
                    ' get one exception object from the Exceptions collection
                    exceptItem = recurPattern.Exceptions.Item(index).AppointmentItem

                    ' display the start date
                    MsgBox("Exception# " + index.ToString + " Starts[" + exceptItem.Start.ToString + "]")

                    index += 1
                End While
            Else
                ' display a message indicating there are no exceptions
                MsgBox("This appointment has no recurrence exception items")
            End If
        Catch
        Finally
            If inspector IsNot Nothing Then Marshal.ReleaseComObject(inspector)
            If apptItem IsNot Nothing Then Marshal.ReleaseComObject(apptItem)
            If recurPattern IsNot Nothing Then Marshal.ReleaseComObject(recurPattern)
            If exceptItem IsNot Nothing Then Marshal.ReleaseComObject(exceptItem)
        End Try

    End Sub


Is there something I can/should do differently in my code to stop this error?

Thanks.
Mike O'Shaughnessy
Software Consultant
Centerprise Information Solutions
http://www.centerprise.ca
Posted 18 Apr, 2008 16:20:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Mike.

Did you add any code to the InspectorActivate event handler?
Posted 19 Apr, 2008 14:45:01 Top
mikeo




Posts: 35
Joined: 2008-04-18
Hi Sergey,

Thanks for your response and sorry for the delay ... no, in the example above I didn't add code to InspectorActivate ...

Thanks,
Mike
Mike O'Shaughnessy
Software Consultant
Centerprise Information Solutions
http://www.centerprise.ca
Posted 01 May, 2008 13:16:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Mike.

What version of Exchange do you use?

Open the first occurrence of the meeting, select "this occurrence", and update the body (creates the first exception)

If I understand you corretly, there is no need to use the code above to reproduce the issue. Am I correct?
Do you get the same error with a new empty add-in?
Posted 01 May, 2008 13:29:02 Top
mikeo




Posts: 35
Joined: 2008-04-18
Hi Sergey,

We are using Exchange 2007.

I get this error as soon as I have executed code that refers to an appointmentItem instance. In order to avoid the error, I can turn "Cached Exchance Mode" ON for testing purposes, but I will have to resolve this before we implement the Add-in in production.

Thanks,
Mike
Mike O'Shaughnessy
Software Consultant
Centerprise Information Solutions
http://www.centerprise.ca
Posted 05 May, 2008 17:17:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Mike.

I think you don't release some Outlook interfaces. As a result, an Outlook inspector or its item hangs in the memory. Please review the add-in code. E.g the following code may produces the issue in your code:
...
exceptCount = recurPattern.Exceptions.Count

...

exceptItem = recurPattern.Exceptions.Item(index).AppointmentItem

....
Posted 07 May, 2008 07:28:08 Top
mikeo




Posts: 35
Joined: 2008-04-18
Hi Sergey,

I'm working on this issue again since we're nearing deployment. In my test app I followed the code suggestion you emailed to me and it worked great (your suggestion was to rewrite my code to dim a variable for the Inspector as well as the AppointmentItem, and release both of them). However, I am now getting the same symptom from a different scenario.

Here is how to reproduce the new scenario:

  • Create a new Outlook 2007 Add-in project in VS2k8 (Add-in Express VSTO 2008)
  • Add a new ADXModule
  • Add a UserControl and add a ListBox to the UserControl
  • Add a TaskPane via the ADXModule properties. Select the UserControl as the control type for the TaskPane.
  • Open an occurrence of a recurring meeting that has at least one exception. Close the meeting inspector. When you open it a second time you will receive a pop error "Cannot read one instance of this recurring appointment. Close any open appointments and try again, or recreate the appointment.


I discovered this after commenting out all of my code and leaving just my add-in with a task pane and custom control. Please note that I do not receive this error when I disable the test add-in (i.e. the issue is not with the integrity of the recurring meeting data). Also note that this issue appears with Exchange Cached Mode OFF.

Please let me know how I can add a task pane to an ADX Outlook add-in without getting this error.

Thanks,
Mike


Mike O'Shaughnessy
Software Consultant
Centerprise Information Solutions
http://www.centerprise.ca
Posted 27 May, 2008 17:54:06 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Mike.

Why do I need to add the ListBox component to the task pane? Does the add-in work fine without the component?

Posted 28 May, 2008 07:40:34 Top
mikeo




Posts: 35
Joined: 2008-04-18
Hi Sergey,

It looks like the listbox is not required - the error still occurs without the ListBox component.

Do you get the same error?

Thanks,
Mike
Mike O'Shaughnessy
Software Consultant
Centerprise Information Solutions
http://www.centerprise.ca
Posted 28 May, 2008 15:25:29 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
No, I didn't manage to reproduce it yet.
Posted 29 May, 2008 11:12:41 Top