IMapiSession exception: Specified cast is not valid

  • Thread starter c2t5Y2xvdWQ
  • Start date Views 1,502
Status
Not open for further replies.
C

c2t5Y2xvdWQ

I'm using Mapi33... trying to get IMapiSession reference using the code

below...

IntPtr iunknownPtr =

Marshal.GetIUnknownForObject(m_OutlookApp.Session.MAPIOBJECT);

IMAPISession imapiSession = (IMAPISession)iunknownPtr;

where m_OutlookApp is an instance of Application from MS.Office.InterOp...

When I run this code inside Outlook via Addin passing m_OutlookApp from

OnConnection... it runs fine,

when I run it from command app, passing an instance of m_OutlookApp using

new Application() I get:

System.InvalidCastException was caught Message="Specified cast is not

valid."

Any idea why or a workaround on how to get an IMapiSession reference from

command line app?

Thanks in advance
 
D

Dmitry Streblechenko

Did you call MAPIInitialize on that thread?

Dmitry Streblechenko (MVP)

-

"skycloud" <skycloud> wrote in message

news:F2F28A20-3D10-4CDF-B5E4-0EC64440E390@microsoft.com...
> I'm using Mapi33... trying to get IMapiSession reference using the code
> below...

> IntPtr iunknownPtr =
> Marshal.GetIUnknownForObject(m_OutlookApp.Session.MAPIOBJECT);
> IMAPISession imapiSession = (IMAPISession)iunknownPtr;

> where m_OutlookApp is an instance of Application from MS.Office.InterOp...

> When I run this code inside Outlook via Addin passing m_OutlookApp from
> OnConnection... it runs fine,

> when I run it from command app, passing an instance of m_OutlookApp using
> new Application() I get:

> System.InvalidCastException was caught Message="Specified cast is not
> valid."

> Any idea why or a workaround on how to get an IMapiSession reference from
> command line app?

> Thanks in advance
 
Status
Not open for further replies.
Top