473,785 Members | 2,369 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 1591
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
5108
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
4894
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
3651
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
4503
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
3044
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
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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
10155
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
10095
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
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
3
2881
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.