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 and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 12th 07, 05:08 PM posted to microsoft.public.outlook.program_vba
Dhananjay
external usenet poster
 
Posts: 33
Default Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'.

Hi All,
I am developing one VSTO COM addin for outlook 2003 in vb 2005. My
code snippet is as follows. odbcrdr(0) always contains valid entryID.
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' Set connection & command -----
' ----
Dim odbcrdr As OdbcDataReader
odbcrdr = myCmd.ExecuteReader
Dim cnt As Integer = 0
Dim c As Outlook.ContactItem
Dim ns As Outlook.NameSpace
ns = myGlobalApplication.GetNamespace("MAPI")
While odbcrdr.Read
Try
c = Nothing
c = ns.GetItemFromID(odbcrdr(0))
Catch ex As System.Exception
AddTrace("Contact item can not be set for
entryid - " & odbcrdr(0) & vbCrLf & "Exception - " & ex.Message)
MsgBox("Contact item can not be set for entryid
- " & odbcrdr(0) & vbCrLf & "Exception - " & ex.Message,
MsgBoxStyle.Critical Or MsgBoxStyle.SystemModal)
Finally
c = Nothing
End Try
End While
'-------------------------------------------------------------------------------------------------------------------------------------------------------

Now when the count of returned records is greater than 250, I am
always getting error on record 251 -
Exception - Unable to cast COM object of type 'System.__ComObject' to
interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This
operation failed because the QueryInterface call on the COM component
for the interface with IID '{00063021-0000-0000-C000-000000000046}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
This error is always appearing on the record 251! One thing is that,
all these records are on my public folder. (If those entryids are from
personal folder then code is working fine!!)
Please Help!

Thanks,
Dhananjay

  #2  
Old October 12th 07, 05:48 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'.

You are running out of the 255 open messages limit impsed by Exchange.
Release the previously opened contacts using Marshal.ReleaseCOMObject.
Setting the object to null won'r help since the actual call to
IUnknown::Release() happens much later when the GC runs.
Calling GC.Collect() every once in a while is also a good idea.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Dhananjay" wrote in message
oups.com...
Hi All,
I am developing one VSTO COM addin for outlook 2003 in vb 2005. My
code snippet is as follows. odbcrdr(0) always contains valid entryID.
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' Set connection & command -----
' ----
Dim odbcrdr As OdbcDataReader
odbcrdr = myCmd.ExecuteReader
Dim cnt As Integer = 0
Dim c As Outlook.ContactItem
Dim ns As Outlook.NameSpace
ns = myGlobalApplication.GetNamespace("MAPI")
While odbcrdr.Read
Try
c = Nothing
c = ns.GetItemFromID(odbcrdr(0))
Catch ex As System.Exception
AddTrace("Contact item can not be set for
entryid - " & odbcrdr(0) & vbCrLf & "Exception - " & ex.Message)
MsgBox("Contact item can not be set for entryid
- " & odbcrdr(0) & vbCrLf & "Exception - " & ex.Message,
MsgBoxStyle.Critical Or MsgBoxStyle.SystemModal)
Finally
c = Nothing
End Try
End While
'-------------------------------------------------------------------------------------------------------------------------------------------------------

Now when the count of returned records is greater than 250, I am
always getting error on record 251 -
Exception - Unable to cast COM object of type 'System.__ComObject' to
interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This
operation failed because the QueryInterface call on the COM component
for the interface with IID '{00063021-0000-0000-C000-000000000046}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
This error is always appearing on the record 251! One thing is that,
all these records are on my public folder. (If those entryids are from
personal folder then code is working fine!!)
Please Help!

Thanks,
Dhananjay



  #3  
Old October 13th 07, 06:52 AM posted to microsoft.public.outlook.program_vba
Dhananjay
external usenet poster
 
Posts: 33
Default Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'.

Thank you Dmitry for your valuable suggesion.
Actually I was tried releaseCOMObject before, but it was also giving
me the same error.
in Finally block I wrote code like -
'-----------------------------------------------------
Marshal.ReleaseComObject(c)
c = nothing
'-----------------------------------------------------

After that I wrote code like -
'-----------------------------------------------------
Marshal.ReleaseComObject(c)
'-----------------------------------------------------
i.e. not c = nothing in the finally block. etc
But it is always failing on 250th record. Should I try something else?

Thanks again,
Dhananjay

  #4  
Old October 13th 07, 07:56 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.ContactItem'.

Make sure you never use multipel dot notation to avoid implicit variables
created by the compiler and also call GC.Collect().

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Dhananjay" wrote in message
oups.com...
Thank you Dmitry for your valuable suggesion.
Actually I was tried releaseCOMObject before, but it was also giving
me the same error.
in Finally block I wrote code like -
'-----------------------------------------------------
Marshal.ReleaseComObject(c)
c = nothing
'-----------------------------------------------------

After that I wrote code like -
'-----------------------------------------------------
Marshal.ReleaseComObject(c)
'-----------------------------------------------------
i.e. not c = nothing in the finally block. etc
But it is always failing on 250th record. Should I try something else?

Thanks again,
Dhananjay



 




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
How to get Microsoft.Office.Interop.Outlook.TaskItem from the IUnknown (C#) Godandag Add-ins for Outlook 5 April 5th 07 09:39 AM
Which services sends SYSTEM type messags Mr. Smith Outlook - General Queries 0 November 17th 06 12:14 PM
Msdn help for Microsoft.Office.Interop.Outlook members DavidE Add-ins for Outlook 0 August 9th 06 07:45 AM
Type of object for AdvancedSearch Renjith Outlook and VBA 4 May 17th 06 02:13 PM
Move object type Bob Smith Outlook and VBA 1 May 16th 06 07:08 AM


All times are GMT +1. The time now is 12:25 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.