IMapiSession exception: Specified cast is not valid

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
 
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.
Similar threads
Thread starter Title Forum Replies Date
C Problem accessing events for folder "username" Server Threw Exception Using Outlook 1
A Exception message: MapiExceptionLogonFailed: Unable to open message store Exchange Server Administration 1
A Unhandled exception: picture argument should be an image BCM (Business Contact Manager) 0
N _MailItem->GetSendOn(&date) throws an exception Outlook VBA and Custom Forms 1
T exception when I call ActiveDocument.Range(0,0).Editors.Add(-1) Outlook VBA and Custom Forms 2
M Exception from HRESULT: 0x8007000E (E_OUTOFMEMORY) Outlook VBA and Custom Forms 3
N Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) Outlook VBA and Custom Forms 1
L Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) Outlook VBA and Custom Forms 1
R vba rule exception "except with specific words in the sender's add Outlook VBA and Custom Forms 2
S Security exception while opening custom outlook form Outlook VBA and Custom Forms 1
T Search for incoming e-mails for a specified time range Using Outlook 1
M MsgBox when not sending from specified account Outlook VBA and Custom Forms 2
R When rules lose track of "specified folder" Using Outlook 6
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
P move a specified email "From" tag items to a certain folder whenever there is "New Mail" in the inbo Outlook VBA and Custom Forms 5
G Rule - All email from a specified domain Using Outlook 2
mikolajek Digital signing message from a specified account Using Outlook 2
L Outgoing Email attachment error "the system cannot find the file specified" Using Outlook 3
A Error Message: The subject is not trusted for the specified action Outlook VBA and Custom Forms 3
Y How to save a custom form in a specified folder? Outlook VBA and Custom Forms 2
R How to judge what folder the specified entry id is? Outlook VBA and Custom Forms 8
J Specified cast is not valid Outlook VBA and Custom Forms 1

Similar threads

Back
Top