IMapiSession exception: Specified cast is not valid

S

skycloud

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top