This project has moved and is read-only. For the latest updates, please go here.

Accessing MAPIOBJECT fails

Apr 8, 2014 at 11:46 AM

we currently developing an Outlook addin for outlook 2010 and 2013. We want to give Netoffice a try because we think it's an powerfull piece of software.

For our addin we used the aproach to extend the COMAddin class.

No we have the situation that we need access to the MAPIOBJECT of an outlook application session. But we get always an Nullreferenceexception while accessing this MAPIOBJECT.

To reproduce the behaviour the following sample COMAddin should do:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using NetOffice.Tools;
using NetOffice.OutlookApi.Tools;
using NetOffice.OutlookApi;

  * This project shows you the COMAddin base class from the NetOffice tools.
  * Its designed to reduce infrastructure code from your own.
  * You have to set some attributes and thats all. 
  * You see also the host application is available as class instance property. no need for dispose here because the base class do this for you while shutdown.

namespace NetOfficeTools.SimpleOutlookCS45
    [COMAddin("NetOfficeCS45 Sample Outlook Addin", "This Addin shows you the COMAddin base class from the NetOffice Tools", 3)]
    [GuidAttribute("E84FBA68-FDA6-4cf6-A0E7-5F025C0F9867"), ProgId("SimpleOutlookCS45.Addin")]
    public class Addin : COMAddin
        public Addin()
            this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete);
            this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection);

        void Addin_OnStartupComplete(ref Array custom)
            // get the host application version
            string hostVersion = this.Application.Version;
            MessageBox.Show("Host Application Version:" + hostVersion);
                var session = this.Application.Session;
                //here the error occurs....
                var mapi = session.MAPIOBJECT;
            catch (System.Exception ex)
                 MessageBox.Show("Error:" + ex.StackTrace);

        void Addin_OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)

What are my options?

Thanx for help in advance

Best regards
Apr 8, 2014 at 11:50 AM

its NO 1.6 ??

Apr 8, 2014 at 11:53 AM
Edited Apr 8, 2014 at 11:58 AM
Hi Sebastian,

many thanx for your ultra fast reply :)

Yes we use NO 1.6.0. We tried the 1.7.0 preview too. Unfortunatly with the same result.

Apr 8, 2014 at 12:52 PM
the problem is: the MAPIOBJECT com class doesnt implement the IDispatch interface. this is a must-have to use late-binding. i try to access the MAPIOBJECT with vb latebinding and c# dynamics. this works but i can't use any property or method for the MAPIOBJECT instance here (COMException.{"IDispatch wird nicht vom COM-Ziel implementiert."}) This is the first time i see an office class without IDispatch implementation. NO convert the proxy to IDispatch in order to analyze and resolve the corresponding wrapper class. this operation fails and the NullReferenceException occurs. i need few days to anzalyze the com type library and create a workarround(if possible, my current idea is to call the vtable early bind interface directly, not sure this works as expected without problems in all versions and platforms)

as hotfix i suggest i you to use the highest available pia's and use the 'embedd interop types' reference feature. its also versionindependent and its possible to combine both API's if you need events or something like that(embedd interop cant give you events) I want help you as best i can if you need further assistance here.

Gimme few days please to find and create a solution for the problem. currently, im very suprised. :/

Apr 8, 2014 at 2:26 PM
Edited Apr 8, 2014 at 2:27 PM
Hi Sebastian,

many thanx for having a look into this.

My temporary workaround now:
 Microsoft.Office.Interop.Outlook.Application msApp =
                var mapiObj = msApp.Session.MAPIOBJECT;
After some very quick tests i made it seems to work as expected. So both we won some time to find a solution if one exists.

best regards
Apr 8, 2014 at 2:40 PM
exactly. thats what i mean to combine the PIA's and NO.
i'm still suprised because this problem was not detected for a long time :o
yes i know.. its not a mistake, just a little happy accident....(*grrrrrrr)

Oct 23, 2014 at 1:06 AM
Hi Subastian,

Did you ever figure out a way to access the underlying MAPI object without having to rely INTEROP?