473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidCastExce ption with Outlook 2003

Hi

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

The line of code is:

objAppointmentI tem = objItems.GetFir st

Does anyone know what to do???
Peter
Nov 20 '05 #1
4 1593
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.c om:
Hi

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

The line of code is:

objAppointmentI tem = objItems.GetFir st

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 objAppointmentI tem as AppointmentItem

Dim obj As Object = objItems.GetFir st()

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

Hope this helps
Jay

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

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

The line of code is:

objAppointmentI tem = objItems.GetFir st

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 objAppointmentI tem as AppointmentItem

Dim obj As Object = objItems.GetFir st()

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

Hope this helps
Jay

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

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

The line of code is:

objAppointmentI tem = objItems.GetFir st

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.c om...

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 objAppointmentI tem as AppointmentItem

Dim obj As Object = objItems.GetFir st()

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

Hope this helps
Jay

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

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

The line of code is:

objAppointmentI tem = objItems.GetFir st

Does anyone know what to do???
Peter

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3700
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox Matter matters= v.Matters; comboBox1.Items.AddRange(matters);
4
5109
by: Max | last post by:
Hi, I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003. The user selects the email client and clicks the button. The only things happening will be: a new email is created and some text is placed in the body, then the email window is displayed. The user can close the window or select some recipients and send the message. I would like some info on how to do this correctly....
1
4895
by: Joey Lee | last post by:
Hi, I am trying to send mail thru outlook. I have found some code on the web and ws trying it out. I was successful in creating a mail in the draft folder of outlook, however hangs for a long time during the sending of the mail. Snippet code as below ------------------------------------------- using Outlook = Microsoft.Office.Interop.Outlook; //using the 11.0 object
4
2664
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am receiving these hidden values like the following:
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> System.InvalidCastException: Specified...
5
3652
by: TM | last post by:
I would like to write a little app in Visual Basic .net as an add-in to Outlook 2003 so that I can quickly get a list of contact names and email addresses, then when I click on a name or email address, I want to open a new mail message to that person. I don't want to send the message, just open a new blank email so that I can make it easier to send messages. Any idea how I could find out more about how to do this ?
9
3092
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in oItems" loop. After about 250 contacts, the program gives an InvalidCastException Error on the for each loop. I notice that Outlook's memory keeps increasing (using the task manager) until it reaches around 20,000K. When I run the program a second...
11
4506
by: Maximus | last post by:
Hi all, Has anyone been able to reterive the gradient selection colors used in outlook 2003? Basically, I have a grid showing a list of records and my client wants the selected row to have the same selection gradient back color as Outlook 2003 has on its left pane. The selected pane in Outlook 2003 have a gradient orange color for blue color scheme in XP. This gradient color changes according to the color schemes of the windows XP. Can...
5
3045
by: John A. Bailo | last post by:
I have a program that I'm converting from Outlook 2000 to Outlook 2003. It basically opens Outlook and iterates through a series of items in a public folder. I was able to run this as a scheduled task overnight. But now, it seems to want to have me be logged in already or it will not log into Outlook.
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.