Fixed font Subject: Programmatic Interface (API) into Microsoft Outlook Calendar
Author: Rico Date: 26 Jun 2009
References:
My goal is to access my Microsoft Outlook Calendar from a C# program.
If you know VB I can work with it.

I started with:

http://stackoverflow.com/questions/90899/net-get-all-outlook-calendar-items

and wrote the following:
---------------------------------------------------

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder calendarFolder = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
calendarFolder = mapiNamespace.GetDefaultFolder
(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in
calendarFolder.Items)
{
System.Console.WriteLine(item.Location);
}

---------------------------------------------------


Yesterday, I kept getting this exception at the start of the foreach
loop:

System.InvalidCastException was unhandled

Message="Unable to cast COM object of
type 'System.__ComObject' to interface
type 'Microsoft.Office.Interop.Outlook.AppointmentItem'.

This operation failed because the QueryInterface call on the COM
component
for the interface with IID '{00063033-0000-0000-C000-000000000046}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

---------------------------------------------------

This morning, when I logged in, the program ran perfectly.

This afternoon, I am getting the same exception.

What is unique or special about COM that I need to know in order to
avoid these exceptions?

Is there some sort of system configuration that I need to turn on?
Something in the registry?

Thanks.