Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook - Using Forms (http://www.outlookbanter.com/outlook-using-forms/)
-   -   Unable to cast COM object" error (http://www.outlookbanter.com/outlook-using-forms/89695-unable-cast-com-object-error.html)

Emrak April 29th 09 06:43 PM

Unable to cast COM object" error
 
Hey all, I receive the following error when I try to iterate through and
access emails and their associated attachments:
Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Interop.Outlook._MailItem'.

I will demonstrate the 3 main attempts (of the trillion I've tried). :-/

Attempt #1:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

foreach (MailItem oMessage in oFldr.Items)
{
....
}

Attempt #2:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

foreach (Object oMessage in oFldr.Items)
{
....
}

Attempt #3:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

for (int i = 1; i = oFldr.Items.Count; i++)
{
Object o = oFldr.Items[i];
Type t = o.GetType();
}

I know that people are wont to send in email types other than MailItem. For
instance, there are several "discussion" items in the email box in question.
I've tried to isolate those, but when I run #3, I find that "oFldr.Items[i]"
has a type of "System.__ComObject" which is unhelpful to me. All I'm trying
to do is grab email messages and discussion items and process them.
Unfortunately, it bombs out.

Help!

Emrak April 29th 09 07:06 PM

Unable to cast COM object" error
 
The main issue here is I'm unable to reach the mail items and discussion
items. I just can't. Any example code would be helpful.

Dmitry Streblechenko May 1st 09 07:49 AM

Unable to cast COM object" error
 
Are you sure you really have a MailItem object?
You could also have ReportItem, ContactItem, etc.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Emrak" wrote in message
...[i]
Hey all, I receive the following error when I try to iterate through and
access emails and their associated attachments:
Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Interop.Outlook._MailItem'.

I will demonstrate the 3 main attempts (of the trillion I've tried). :-/

Attempt #1:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

foreach (MailItem oMessage in oFldr.Items)
{
...
}

Attempt #2:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

foreach (Object oMessage in oFldr.Items)
{
...
}

Attempt #3:
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.Folders["Public Folders"].Folders["Test"]

for (int i = 1; i = oFldr.Items.Count; i++)
{
Object o = oFldr.Items[i];
Type t = o.GetType();
}

I know that people are wont to send in email types other than MailItem.
For
instance, there are several "discussion" items in the email box in
question.
I've tried to isolate those, but when I run #3, I find that
"oFldr.Items"
has a type of "System.__ComObject" which is unhelpful to me. All I'm
trying
to do is grab email messages and discussion items and process them.
Unfortunately, it bombs out.

Help!





All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com