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 » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Specified cast is not valid



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 8th 09, 12:13 PM posted to microsoft.public.outlook.program_addins
Janni
external usenet poster
 
Posts: 1
Default Specified cast is not valid

I'm developing a VSTO (second edition) addin for Outlook. One of my
customers gets the following error:

"System.InvalidCastException: Specified cast is not valid.
at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal
(Int32 errorCode, IntPtr errorInfo)
at
System.Runtime.InteropServices.CustomMarshalers.En umerableViewOfDispatch.GetEnumerator
()
at System.Collections.IEnumerable.GetEnumerator() "

when looping through the items in the calendar folder.

Dim oFolder As MsOutlook.MAPIFolder = oSession.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderCalendar)
Dim oItems As MsOutlook.Items = m_oFolder.Items

For Each oItem As Object In oItems
....
Next

Anyone who has any clue about the cause of this error?

  #2  
Old April 8th 09, 02:57 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Specified cast is not valid

What line is the exception thrown on? Is it in the For Each line?

Does the exception get thrown if the code is changed to use a normal For
loop with a loop counter?

Dim count as Integer = oItems.Count
Dim i As Integer
For i = 1 To count
' code here
Next

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Janni" wrote in message
...
I'm developing a VSTO (second edition) addin for Outlook. One of my
customers gets the following error:

"System.InvalidCastException: Specified cast is not valid.
at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal
(Int32 errorCode, IntPtr errorInfo)
at
System.Runtime.InteropServices.CustomMarshalers.En umerableViewOfDispatch.GetEnumerator
()
at System.Collections.IEnumerable.GetEnumerator() "

when looping through the items in the calendar folder.

Dim oFolder As MsOutlook.MAPIFolder = oSession.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderCalendar)
Dim oItems As MsOutlook.Items = m_oFolder.Items

For Each oItem As Object In oItems
...
Next

Anyone who has any clue about the cause of this error?


 




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
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
'not a valid win 32 application' les60leeds Outlook - Using Contacts 1 October 31st 07 01:51 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
contacts.pst not valid binnsdrafting Outlook - Using Contacts 2 August 13th 06 04:32 AM
Parameters not valid Suedra Outlook - Calandaring 0 February 24th 06 12:57 AM


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