Need help Casting "System.__ComObject" to "Ou

Posted by Admin on 22-Jun-2009 09:21

Hi All,

I'm trying to get my Outlook Calendar appointments into Progress and I ran into the following problem:

I can iterate through all the appointment but when I try to cast them into an "AppointmentItem" progress gives me the following:

Invalid cast from System.__ComObject to Microsoft.Office.Interop.Outlook.AppointmentItem

I’m using Outlook version 12.

The following is a little code example in progress:


     DEFINE VARIABLE CallApp AS CLASS Microsoft.Office.Interop.Outlook.ApplicationClass NO-UNDO.
     DEFINE VARIABLE CallNamespace AS CLASS Microsoft.Office.Interop.Outlook.NameSpace NO-UNDO.
     DEFINE VARIABLE CallInbox AS CLASS Microsoft.Office.Interop.Outlook.FolderClass NO-UNDO.
     DEFINE VARIABLE CallMapi AS CLASS Microsoft.Office.Interop.Outlook.MAPIFolder NO-UNDO.

     CallApp = NEW Microsoft.Office.Interop.Outlook.ApplicationClass().
     CallNamespace = CallApp:GetNamespace("MAPI").
     CallMapi = CallNamespace:GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders:olFolderCalendar).
     DEFINE VARIABLE CallItems AS CLASS Microsoft.Office.Interop.Outlook.Items NO-UNDO.
     CallItems = cCallMapi:Items.
     DEFINE VARIABLE iCallCount AS INTEGER NO-UNDO.
     DEFINE VARIABLE CallAppoint AS CLASS Microsoft.Office.Interop.Outlook.AppointmentItem NO-UNDO.
     DO iCallCount = 1 TO CallItems:Count:
        CallAppoint = CAST(CallItems:Item[iCallCount],Microsoft.Office.Interop.Outlook.AppointmentItem).                                                                              
     END.


I am absolutely sure that the object type is of type "AppointmentItem" because I’ve successfully achieved the above using only .NET in Visual Studio.

Am I doing something wrong or is this a bug?

Thanks in advance,

Niels

All Replies

Posted by Admin on 23-Jun-2009 11:30

Hi Niels,

I don't find anything suspicious in your code and I guess in C# the code would very much work like that. I also tried CASTing to the AppointmentItemClass (the ComObject that implements the AppointmentItem Interface) with no difference.

My feeling is, that Progress does not support ComInterop in the GUI for .NET - maybe Progress' type validation (based on the Reflection API ?) is to strict, does not recognize the Queriable Interface.

Did you talk to tech-support about this already?

Mike

Posted by Admin on 24-Jun-2009 01:46

Hi Mike,

I have sent an e-mail to Tech-Support yesterday.

I will post the result here.

Niels

Posted by Admin on 05-Jan-2010 16:38

Hi Niels,

I was wondering if you every found a solution. I need to do the same thing but with email messages.

Regards,

Jim

Posted by Admin on 05-Jan-2010 16:45

By the way: I ran into the same issue when trying to use Enterprise Architects ".NET" API. Found out it's also nothing more than a COM-Wrapper.

I gave up and use the COM-Object as a COM-Object (Automation Server). Avoiding the COM-Interop layer. Works in 10.2A/10.2B as it does since V8 - but I'm really missing the strong typing :-(

I see no reason why you couldn't continue to use the Outlook objects as COM-Objects.

Posted by Matt Baker on 06-Jan-2010 07:55

This sample code works fine in 10.2B.  The com control wrapper classes (identified by a specific annotation on the class in the .NET IL code) were filtered by the AVM to be unusable in 10.2A due to limitations.  This limitation is removed in 10.2B.

Posted by Admin on 06-Jan-2010 09:11

Thanks Matthew.

I believe we just recieved our 10.2B licenses so I'll download it and give it a try.

JL

Posted by Admin on 06-Jan-2010 17:42

Indeed it looks much better on 10.2B, did a quick test with Interop.EA.dll (Enterprise Architect):

DEFINE VARIABLE oRepository AS EA.Repository  NO-UNDO . /* That's an Interface */

DEFINE VARIABLE oModel      AS EA.IPackage    NO-UNDO .

ASSIGN oRepository = NEW EA.RepositoryClass () .

oRepository:OpenFile ("C:\Work\SmartComponents4NET\SmartComponents.eap") .

oModel = CAST(CAST(oRepository:Models, EA.Collection):GetAt(0), EA.IPackage) .

MESSAGE oRepository:EAEdition:ToString ()

        CAST(CAST(oModel:Packages, EA.Collection):GetAt(0), EA.IPackage):NAME

    SKIP .

That used to fail on 10.2A!

changed oRepository from Interface IRepository to interface Repository.

This thread is closed