A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

IMapiSession exception: Specified cast is not valid



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 12th 09, 01:02 AM posted to microsoft.public.outlook.program_addins
skycloud
external usenet poster
 
Posts: 2
Default IMapiSession exception: Specified cast is not valid

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
Ads
  #2  
Old May 12th 09, 04:46 AM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default IMapiSession exception: Specified cast is not valid

Did you call MAPIInitialize on that thread?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"skycloud" wrote in message
...
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



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cast COM object" error Emrak Outlook - Using Forms 2 May 1st 09 07:49 AM
Unable to cast COM object" error Emrak Add-ins for Outlook 5 April 30th 09 07:01 PM
Specified cast is not valid Janni Add-ins for Outlook 1 April 8th 09 02:57 PM
Unable to cast object of type 'System.__ComObject' to type 'Microsoft.Office.Interop.Outlook.ApplicationClass' John Yovas Add-ins for Outlook 2 September 12th 08 04:23 PM
Usage of IMAPISession from IExchExt Petr Nehez Add-ins for Outlook 1 December 12th 06 04:40 PM


All times are GMT +1. The time now is 09:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.