A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Unable to cast COM object" error



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 29th 09, 06:43 PM posted to microsoft.public.outlook.program_forms
Emrak
external usenet poster
 
Posts: 6
Default 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!
  #2  
Old April 29th 09, 07:06 PM posted to microsoft.public.outlook.program_forms
Emrak
external usenet poster
 
Posts: 6
Default 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.
  #3  
Old May 1st 09, 07:49 AM posted to microsoft.public.outlook.program_forms
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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!



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Request using XML HTTP object throws "Access is Denied" error Sangeeta[_2_] Outlook and VBA 0 February 11th 09 10:30 AM
Unable to cast object of type 'System.__ComObject' to type 'Microsoft.Office.Interop.Outlook.ApplicationClass' John Yovas Add-ins for Outlook 2 September 12th 08 04:23 PM
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. Dhananjay Outlook and VBA 3 October 13th 07 07:56 AM
Unable to reply "null or not an object" Dave Outlook Express 1 November 13th 06 07:04 PM
“The operation failed. An object could not be found. Unable to..." Milton Outlook - Calandaring 0 August 3rd 06 04:07 PM


All times are GMT +1. The time now is 12:28 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-2025 Outlook Banter.
The comments are property of their posters.