Specified cast is not valid

Status
Not open for further replies.
J

Janni

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.ThrowExceptionForHRInternal

(Int32 errorCode, IntPtr errorInfo)

at

System.Runtime.InteropServices.CustomMarshalers.EnumerableViewOfDispatch.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?
 
K

Ken Slovak - [MVP - Outlook]

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

"Janni" <janni.kajbrink@hotmail.com> wrote in message

news:11495981-e5ec-4efa-b616-c698bef62550@g37g2000yqn.googlegroups.com...
> 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.ThrowExceptionForHRInternal
> (Int32 errorCode, IntPtr errorInfo)
> at
> System.Runtime.InteropServices.CustomMarshalers.EnumerableViewOfDispatch.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?
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C IMapiSession exception: Specified cast is not valid Outlook VBA and Custom Forms 1
T Search for incoming e-mails for a specified time range Using Outlook 1
M MsgBox when not sending from specified account Outlook VBA and Custom Forms 2
R When rules lose track of "specified folder" Using Outlook 6
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
P move a specified email "From" tag items to a certain folder whenever there is "New Mail" in the inbo Outlook VBA and Custom Forms 5
G Rule - All email from a specified domain Using Outlook 2
mikolajek Digital signing message from a specified account Using Outlook 2
L Outgoing Email attachment error "the system cannot find the file specified" Using Outlook 3
A Error Message: The subject is not trusted for the specified action Outlook VBA and Custom Forms 3
Y How to save a custom form in a specified folder? Outlook VBA and Custom Forms 2
R How to judge what folder the specified entry id is? Outlook VBA and Custom Forms 8
C Unable to cast object of type 'System.Int32' to type 'System.Byte[ BCM (Business Contact Manager) 1
R Unable to cast COM object" error Outlook VBA and Custom Forms 2
R Unable to cast COM object" error Outlook VBA and Custom Forms 5
Diane Poremsky Could not complete the operation. One or more parameter values are not valid. Using Outlook 0
S The incoming task is not valid ((when users are accepting a Task) Using Outlook 5
A webinar.ics is not a valid Internet Calendar file Using Outlook 1
M Is there a reference for the valid XML tags and their options? Using Outlook 3
K message.vcs is not a valid Internet calendar file !! Exchange Server Administration 5
M Can't send email to certain valid email addresses, message says Using Outlook 1
P Valid user cannot be resolved issue Outlook VBA and Custom Forms 5
M Restrict throwing 'Condition is not valid' error Outlook VBA and Custom Forms 5
A Generating valid MAPI URLs for Outlook 2003 Outlook VBA and Custom Forms 2
I one or more parameters not valid 2007 sending email BCM (Business Contact Manager) 2

Similar threads

Top