none
Problem with shared calendars in Overlay View RRS feed

  • Question

  • Hi,

    We have a problem in our addin when the user have an exchange calendar and an additional shared gmail calendar. When in overlay view and the user right click on any appointment in the exchange calendar we evaluate the meetingstatus on a context button in the OnClick event. However, when the gmail calendar is also active an exception occurs. This only happens if you activate the exchange calendar last though.

    So the steps to recreate the issue are:

    1. Add a gmail calendar and show it in overlay view together with your exchange calendar.
    2. Disable and then enable your exchange calendar in the navigationpane
    3. Restart Outlook.
    4. Right click on any appointment from your exchange calendar in the overlay view.

    And here is the code that cause the exception:

    <contextMenus>
    		<contextMenu idMso="ContextMenuCalendarItem">
    			<button id="MyContextMenuCalendarView"
    				 label="ContextMenuCalendarView"
    				 onAction="OnMyButtonClick"
    				/>
    		</contextMenu>
    	</contextMenus>

    Public Sub OnMyButtonClick(control As Office.IRibbonControl)
    
    		Try
    			Dim oSelection As Outlook.Selection = TryCast(control.Context, Outlook.Selection)
    
    			If (oSelection IsNot Nothing AndAlso oSelection.Count = 1) Then
    
    				Dim oCurrentItem As Object = oSelection.Item(1)
    				Dim ai As Outlook.AppointmentItem = Nothing
    
    				If (TypeOf oCurrentItem Is Outlook.AppointmentItem) Then
    					ai = TryCast(oCurrentItem, Outlook.AppointmentItem)
    				End If
    
    				Dim oMeetingStatus As Outlook.OlMeetingStatus = ai.MeetingStatus
    				System.Runtime.InteropServices.Marshal.ReleaseComObject(oCurrentItem)
    			End If
    		Catch ex As Exception
    
    		End Try
    
    	End Sub


    Thursday, June 12, 2014 11:27 AM

Answers

  • As a workaround you may get the EntryID value of the selected item and then use the GetItemFromId method of the Namespace class to get a valid reference. Does it make any sense?
    Thursday, June 12, 2014 2:37 PM
  • Selection isn't necessarily valid for what you want. You can right-click on an item and trigger the context menu handler without selecting the item being right-clicked. In that  case the item won't be in the Selection collection.

    You could file a bug on this, but that could take a long time to fix even if MS decides to fix it.

    A possible workaround might be a hack, but see if it works anyway. When you get the AppointmentItem reference from Control.Context can you use the GetInspector() method to get a valid Inspector object? If you do that and then use Inspector.CurrentItem cast as AppointmentItem  are the properties accessible then?


    Ken Slovak MVP - Outlook

    Tuesday, June 17, 2014 1:57 PM
    Moderator

All replies

  • Hello Steeir,

    Did you try to debug? What line of code causes the issue?

    Did you try to comment all the code in the button's event handler? Does it help?
    Thursday, June 12, 2014 11:55 AM
  • Hi,

    It's when i try to access the MeetingStatus property that the exception occurs:

    Dim oMeetingStatus As Outlook.OlMeetingStatus = ai.MeetingStatus

    System.Runtime.InteropServices.COMException was caught
      ErrorCode=-1525415673
      HResult=-1525415673
      Message=Could not open the item. Try again.
      Source=Microsoft Outlook
      StackTrace:
           at Microsoft.Office.Interop.Outlook._AppointmentItem.get_MeetingStatus()
           at OutlookAddinTest.Ribbon1.OnMyButtonClick(IRibbonControl control)
      InnerException:

    Thursday, June 12, 2014 12:01 PM
  • Do you have any other add-ins installed and registered for Outlook (iTunes)?

    Also please make sure that you have the latest updates and service packs installed for Outlook. You may find more information in the following similar forum threads:

    Error Message "Could not open item. Try again."

    Oulook 2010 (on exchange 2010): "Cannot open this item" after search in online archive on indexed mail

    Thursday, June 12, 2014 12:10 PM
  • Yes, i'm running Outlook 2013 with the latest updates and i have also disabled all other add-ins. The problem remains though. If you examine the appointmentitem you can see that most of the properties says "Could not open the item. Try again.". But if i disable the internet calendar, everything works fine.
    Thursday, June 12, 2014 1:16 PM
  • Did you try to use the Selection property of the Explorer class instead? Do you get a valid object in that case?
    Thursday, June 12, 2014 2:09 PM
  • I tried getting the selection from the active Explorer like this but with the same result. I also changed the property to RecurranceState which doesn't work either.

    	Public Sub OnMyButtonClick(control As Office.IRibbonControl)
    		Try
    			Dim oActiveExplorer As Outlook.Explorer = Globals.ThisAddIn.Application.ActiveExplorer
    			Dim oSelection As Outlook.Selection = oActiveExplorer.Selection
    
    			If (oSelection IsNot Nothing AndAlso oSelection.Count = 1) Then
    
    				Dim oCurrentItem As Object = oSelection.Item(1)
    				Dim ai As Outlook.AppointmentItem = Nothing
    
    				If (TypeOf oCurrentItem Is Outlook.AppointmentItem) Then
    					ai = TryCast(oCurrentItem, Outlook.AppointmentItem)
    					Dim oRecurranceState As Outlook.OlRecurrenceState = ai.RecurrenceState
    				End If
    
    				System.Runtime.InteropServices.Marshal.ReleaseComObject(oActiveExplorer)
    				System.Runtime.InteropServices.Marshal.ReleaseComObject(oSelection)
    				System.Runtime.InteropServices.Marshal.ReleaseComObject(oCurrentItem)
    			End If
    		Catch ex As Exception
    
    		End Try
    	End Sub

    Thursday, June 12, 2014 2:32 PM
  • As a workaround you may get the EntryID value of the selected item and then use the GetItemFromId method of the Namespace class to get a valid reference. Does it make any sense?
    Thursday, June 12, 2014 2:37 PM
  • Ok, thanks for the help. So is this a bug?
    Thursday, June 12, 2014 3:14 PM
  • Don't know, but I have already seen such behavior before. Did it help?
    Thursday, June 12, 2014 3:37 PM
  • In my test project I was able to get a valid AppointmentItem by casting the first item of the Selection to an AppointmentItem and then use the EntryID I need to get the valid one. So it works, but I'm not sure if it's the most efficient way to do it.

    	Public Sub OnMyButtonClick(control As Office.IRibbonControl)
    		Try
    			Dim oSelection As Outlook.Selection = TryCast(control.Context, Outlook.Selection)
    
    			If (oSelection IsNot Nothing AndAlso oSelection.Count = 1) Then
    
    				Dim oCurrentItem As Object = oSelection.Item(1)
    				Dim ai As Outlook.AppointmentItem = Nothing
    				Dim ai2 As Outlook.AppointmentItem = Nothing
    
    				If (TypeOf oCurrentItem Is Outlook.AppointmentItem) Then
    					ai = TryCast(oCurrentItem, Outlook.AppointmentItem)
    					Dim oSession As Outlook.NameSpace = Globals.ThisAddIn.Application.Session
    					ai2 = CType(oSession.GetItemFromID(ai.EntryID), Outlook.AppointmentItem)
    					Dim oRecurranceState As Outlook.OlRecurrenceState = ai2.RecurrenceState
    					System.Runtime.InteropServices.Marshal.ReleaseComObject(ai2)
    					System.Runtime.InteropServices.Marshal.ReleaseComObject(oSession)
    				End If
    
    				System.Runtime.InteropServices.Marshal.ReleaseComObject(oCurrentItem)
    			End If
    		Catch ex As Exception
    
    		End Try
    	End Sub



    Friday, June 13, 2014 7:37 AM
  • Thank you for confirming and sharing your code for other forum readers.
    Friday, June 13, 2014 9:52 AM
  • But now i realized that this doesn't work with recurring appointments, because is that case the EntryID is also unavailable.
    Friday, June 13, 2014 12:33 PM
  • Is the IsRecurring property available on the appointment item? If so you can check for recurrence.

    I'm wondering if appointmentitem.Parent works in the case of recurrence? If so a non-recurring item's Parent would be the folder, a recurring item's parent would be the master appointment, You might be able to get a valid EntryID from that.


    Ken Slovak MVP - Outlook

    Friday, June 13, 2014 2:01 PM
    Moderator
  • Hi,

    Yes, IsRecurring works. But unfortunately AppointmentItem.Parent also generates the same exception.

    Monday, June 16, 2014 11:51 AM
  • But even if I could get hold of the EntryID of the master appointment, how would i fetch the current instance of the recurring appointment without OriginalDate?
    Monday, June 16, 2014 12:56 PM
  • If you could get the EntryID you'd have to do what you normally do with a recurring series. You parse the recurrence pattern and look for one closest to the date you want. If that one is missing you go to Exceptions and see if it's there or was deleted.

    Ken Slovak MVP - Outlook

    Monday, June 16, 2014 2:03 PM
    Moderator
  • Yes, but in this case I get the AppointmentItem from control.Context, so without accessing it's properties I can't know which instance of the appointment is currently selected or which date to look for. 

    Tuesday, June 17, 2014 6:19 AM
  • Selection isn't necessarily valid for what you want. You can right-click on an item and trigger the context menu handler without selecting the item being right-clicked. In that  case the item won't be in the Selection collection.

    You could file a bug on this, but that could take a long time to fix even if MS decides to fix it.

    A possible workaround might be a hack, but see if it works anyway. When you get the AppointmentItem reference from Control.Context can you use the GetInspector() method to get a valid Inspector object? If you do that and then use Inspector.CurrentItem cast as AppointmentItem  are the properties accessible then?


    Ken Slovak MVP - Outlook

    Tuesday, June 17, 2014 1:57 PM
    Moderator