468,771 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

InvalidCastException with Outlook 2003

Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter
Nov 20 '05 #1
4 1455
Hi,

Enclose it in a try catch block. I would also turn option strict on.
Make sure you use ctype or directcast to convert between types.

Ken
--------------

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl>
wrote in message news:tu********************************@4ax.com:
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #2
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter

Nov 20 '05 #3

Thx, it works now.

Outlook 2003 is different than 2000. With 2000 i don't have had this
error

On Tue, 8 Jun 2004 08:14:29 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter


Nov 20 '05 #4
Peter,
Remember that a folder may have multiple kind of Items in the folder. I
suspect in Outlook 2000 you only had Appointment Items in the folder, hence
you code works. Where as with Outlook 2003 you now have a second kind of
item in that folder, hence the exception.

Also using SetColumns causes the type of item to change...

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrote
in message news:0j********************************@4ax.com...

Thx, it works now.

Outlook 2003 is different than 2000. With 2000 i don't have had this
error

On Tue, 8 Jun 2004 08:14:29 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
Peter,
In addition to the other comments.

Use the TypeOf operator to ensure that you have an object of the type you
are expecting...

Dim objAppointmentItem as AppointmentItem

Dim obj As Object = objItems.GetFirst()

If TypeOf obj Is AppointmentItem Then
objAppointmentItem = DirectCast(obj, AppointmentItem)
' do stuff with objAppointmentItem
End If

Hope this helps
Jay

"Peter van der Veen" <pvdveenRe_move_This @ no-spam-ming.vanbrug.nl> wrotein message news:tu********************************@4ax.com...
Hi

In my VB.net application i got on different times (and not allways) an
System.InvalidCastException.

The line of code is:

objAppointmentItem = objItems.GetFirst

Does anyone know what to do???
Peter

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joey Lee | last post: by
5 posts views Thread by TM | last post: by
5 posts views Thread by John A. Bailo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.