InvalidCastException when using Custum Form (OL2003) VS.2003 (2005)

  • Thread starter Thread starter Frank Sharp
  • Start date Start date
F

Frank Sharp

Running XP OL2003, VS 2002 pro, I wrote an Outlook Addin.. worked fine.
Did something like: process AppointmentItems based on a Custom Form
(MessageClass= IPM.Appointment.Reservation) like:
Dim objAppts As Items
Dim objAppt As AppointmentItem
objNS = objApplication.GetNamespace("MAPI")
objAppts =
objNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Folders.Item("Reservations").Items
objAppts.IncludeRecurrences = True
objAppt = objAppts.Item(1)

(just an example.. I know how to write AddIns..everything worked fine..)

Then: Installed VS 2005 Pro. From this moment on I got an
InvalidCastException at this line:
objAppt = objAppts.Item(1)
(still running this AddIn under VS 2002.. did nothing with VS 2005, just
installed it)

Wrote a Win.exe to test this; found out: after installing VS2005 I get the
InvalidCastException in VS2002 if the messageclass is not exactly
“IPM.Appointment”; before it also worked with “IPM.Appointment.Reservation”.
To prevent some answers that won’t help:
This AddIn uses Framework 1.1:
'DefaultDomain': 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll'
geladen, keine Symbole geladen.
'Domain2': 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll'
geladen, keine Symbole geladen.
...and so on..(german version..)
TypeName(objAppts.Item(1)) is "AppointmentItem" (no distribution list in
this folder..just AppointmentItems with messageclass
IPM.Appointment.Reservation.. I know all this standard answers..and it
worked fine before installing VS2005)

What I tried so far: uninstalled VS 2005, uninstalled Framework 2.0.. no
luck.. same result..
Uninstalled Framework 1.1, 1.0; reinstalled Framework 1.0, 1.1..Setup repair
of VS 2002.. no luck..

Please help.
Thank you, Frank
 
That sounds like a bug, it should be checking for prefix of MessageClass,
not the entire MessageClass string. Possibly too anal type checking.

Have you tried casting the item into an AppointmentItem?
 
Thank you for your quick reply.
Yes, I tried Ctype and directcast,
also tried to Dim objAppt as Object..., tried to use ItemsClass and
ApointmentItemClass instead ..and so on..
...same result.. and as I said, everything worked fine till I installed VS
2005.
My main problem now is that I can't work on this program now on this
machine,
even after uninstalling VS 2005 and Framework 2.0.
Although.. uninstalling VS 2005 doesn't uninstall everything..
I still see the Device Emulator, Document Explorer, SQL Server 2005, SQL
2005 Mobile Dev Tools,
SQL Native Client, SQL VSS Writer, Visual J+ 2.0. Redist. Package, Visual J#
2.0 Redist. Lang.Pack -DEU (german),
MSXML 6.0 Parser.

I did a full install of VS 2005. Maybe I should try to uninstall this left
over components.. I didn't do it because I'm not sure if I should do it in a
special order and I don't want to mess up the machine completly..

Thank you, Frank
 
Additional Information:
I used a Outlook.exe.config file for Outlook to force the use of Framework
1.1 for my AddIn:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v1.1.4322"/>
</startup>
</configuration>

I tried it now with a simple Win.exe and Framework 1.0 with the same result:
(If I use the OlDefaultFolders.olFolderCalendar Items I get just
AppointmentItems with MessageClass IPM.Appointment and no error message..)

Private Sub GetAppointments()
Dim objApplication As Application
Dim objNS As [NameSpace]
Dim objAppts As Items
Dim objAppt As AppointmentItem
Try
objApplication = CreateObject("Outlook.Application")
objNS = objApplication.GetNamespace("MAPI")
objAppts =
objNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Folders.Item("RB").Items
objAppts.IncludeRecurrences = True
Debug.WriteLine(objAppts.Item(1).messageclass)
objAppt = CType(objAppts.Item(1), AppointmentItem)
MsgBox("OK")
Catch CastException As System.InvalidCastException
MsgBox("Error: " & CastException.Message)
Debug.WriteLine(CastException.Message)
Catch ex As System.Exception
MsgBox("Error: " & ex.Message)
Finally
objAppt = Nothing
objAppts = Nothing
objNS = Nothing
objApplication = Nothing
End Try
End Sub

'DefaultDomain': 'c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll'
geladen, keine Symbole geladen.
'TestOLCastError': 'C:\Dokumente und Einstellungen\Franz.Scharf\Eigene
Dateien\Visual Studio-Projekte\TestOLCastError\bin\TestOLCastError.exe'
geladen, Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\system.windows.forms\1.0.3300.0__b77a5c561934e089\system.windows.forms.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\system\1.0.3300.0__b77a5c561934e089\system.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\system.drawing\1.0.3300.0__b03f5f7f11d50a3a\system.drawing.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\accessibility\1.0.3300.0__b03f5f7f11d50a3a\accessibility.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\microsoft.visualbasic\7.0.3300.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\microsoft.office.interop.outlook\11.0.0.0__71e9bce111e9429c\microsoft.office.interop.outlook.dll'
geladen, keine Symbole geladen.
'TestOLCastError.exe':
'c:\windows\assembly\gac\system.xml\1.0.3300.0__b77a5c561934e089\system.xml.dll'
geladen, keine Symbole geladen.
IPM.Appointment.Reservierung
'TestOLCastError.exe':
'c:\windows\assembly\gac\mscorlib.resources\1.0.3300.0_de_b77a5c561934e089\mscorlib.resources.dll'
geladen, keine Symbole geladen.
Die angegebene Umwandlung ist ungültig. (<< that's just the german
errormessage for an InvalidCastError)
Das Programm "[2420] TestOLCastError.exe" wurde mit Code 0 (0x0) beendet.
 
After uninstalling Device Emulator, Document Explorer, SQL Server 2005, SQL
2005 Mobile Dev Tools,
SQL Native Client, SQL VSS Writer, Visual J+ 2.0. Redist. Package, Visual J#
2.0 Redist. Lang.Pack -DEU (german),
and MSXML 6.0 Parser I got rid of the InvalidCastError.



I didn't have the time to check out which one of these components caused the
problem.



If somebody knows where and how to report this Bug, please let me know.

I will follow this thread..

Hope it helps somebody with the same problem.



Regards, Frank.
 
Back
Top