outlookoutlook-redemptionappointment

Unable to cast COM object of type 'System.__ComObject' to interface type 'Redemption.RDOAppointmentItem'


The code below works fine on five PC's but it's failing on one. I had the same user login to a VM and the code ran fine. It's failing at the foreach loop where I cast "RDOAppointmentItem item in calendar.Items".

Here's the exception returned:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Redemption.RDOAppointmentItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{4959BA11-F9D0-4E57-AA7E-125636EEE44A}' failed due to the following error: No such interface supported (0x80004002 (E_NOINTERFACE)).

Am I failing to cast or account for something in my code for this one users machine specific issue?

RDOSession session = null;
RDOFolder calendar = null
 try
 {
    session = new RDOSession();
    session.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, true, System.Reflection.Missing.Value, false);

    calendar = session.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);
 
    foreach (RDOAppointmentItem item in calendar.Items)
    { //do stuff}

Solution

  • It is theoretically possible to have items other than appointments in the Calendar folder. I have a couple ghost items like that - not sure where they came from. You might want to dynamically check if the item is indeed RDOAppointmentItem:

    foreach (RDOMail entry in calendar.Items)
    {
       if (entry is RDOAppointmentItem item)
       {
           //do stuff
       } 
    }