none
MAPI initialization fails after upgrade to .Net 4.7 and latest 2010 MAPI Headers. RRS feed

  • Question

  • Hi,

    I have a CRM Outlook add-in which gets and sets some custom property to an outlook activity (mail, meeting, task..).

    The source code uses the following managed code snippet during this process to initialize MAPI Environment.

    namespace MAPIWrapper 
    {
    Environment::Environment()
    {
    
    MAPIINIT_0* minit = new MAPIINIT_0();
    minit->ulFlags = MAPI_MULTITHREAD_NOTIFICATIONS | 0x8;
    minit->ulVersion = MAPI_INIT_VERSION;
    						
    HRESULT hr = MAPIInitialize(minit);
    
    if (hr != S_OK)
    {
    WrapperException^ wrapEx = gcnew WrapperException("MAPI Initialization failed",FaultCode::MAPI);							throw wrapEx;
    }					
    }
    Environment::~Environment()
    {
    MAPIUninitialize();
    }
    Environment^ Environment::GetInstance()
    {
    try
    {
    if(m_environment == nullptr)
    {
    m_environment = gcnew Environment();
    }
    }
    catch(Exception^ ex)
    {
    String^ errMsg = ex->Message;
    errMsg+= " Failed to initialize environment.";
    WrapperException^ wrapEx = gcnew WrapperException(errMsg,FaultCode::MAPI);
    throw wrapEx;
    }
    return m_environment;
    }
    
    }

    The above code was working until I upgraded the solution project to VS 2017 targeting .NET 4.7 framework from VS2010 .NET 4.0 target Framework, also I had to install the latest 2010 MAPI headers in this upgrade process.

    Now, the above code throws an exception while initializing MAPI environment and it leads to an error message in outlook saying "Either there is no default mail client or the current mail client cannot fulfill the messaging request......."

    Could anybody please help me understand what can be the issue here and how the same can be resolved?

    Is this .NET framework/MAPI headers upgrade causing the issue or I am missing something?

    I am using the Outlook 2016 32-bit.

    Regards,

    Pratik Prakash


    Tuesday, March 20, 2018 2:08 PM

Answers

  • That means the bitness of your app is wrong. It must match the bitness of Outlook, not the host OS. Make sure not to use "Any CPU" - build as x86 or as x64 depending on which flavor of Outlook you want to support.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 22, 2018 3:54 PM

All replies

  • How do you find and load the MAPI system? You need to of that dynamically (LoadLibrary) - see MFCMAPI source code for an example on how that needs to be done.

    If you are running inside the outlook.exe address space (COM addin), you can just attach (GetModuleHandle) to the already loaded olmapi32.dll.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, March 20, 2018 3:19 PM
  • Hi Pratik Prakash,

    This issue may occur if the Outlook registry key is corrupted. When other programs try to use the Outlook Simple MAPI interface, they cannot retrieve the required information from the registry.

    To resolve this issue, you must first remove the corrupted Outlook registry key, and then perform a Detect and Repair operation to have Outlook rebuild the key. To do this, follow these steps. Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry.

    For detailed steps, You can refer link below may help you to solve the issue.

    "Either there is no default mail client or the current mail client cannot fulfill the messaging request" error message when you send e-mail from third-party program in Outlook

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 21, 2018 7:38 AM
    Moderator
  • This error happen if the application loads a stub MAPI dll from the Windows folder. The MAPI system must be loaded dynamically instead of statically linking to mapi32.dll. 


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Wednesday, March 21, 2018 4:09 PM
  • Hi Dmitry,

    Thank you for your inputs!

    To explain the scenario in detail :

    I am using an external application (CRM client application) to create a new activity (mail, meeting,...) and the same is failing (the above-mentioned error) in case of Outlook 32-bit installation, while it works in Outlook 64-bit environment.

    We have a VC++ project - MAPIWrapper which uses MAPI stub (mapi32.dll) to use (get/set) Outlook Item properties and we do load the MAPI system dynamically.

    Also, we have 2 versions of MAPIWrapper - 64 bit and 32 bit to be used dynamically depending on the type/bitness of Client and Outlook installs.

    Now, on further investigation, I found out that even though the client (external application) is running under 32-bit process and Outlook is 32-bit, it tries to load the 64-bit version of MAPIWrapper due to which, it throws the error.

    This issue started just after upgrade of my project/Add-in to VS2017, .NET 4.7, Windows SDK 10.0, and installation and explicit referring to latest 2010 MAPI headers to the project.

    And, if I revert back the changes all the functionalities work as expected. I am still clueless what could be going wrong here.


    Thursday, March 22, 2018 6:48 AM
  • That means the bitness of your app is wrong. It must match the bitness of Outlook, not the host OS. Make sure not to use "Any CPU" - build as x86 or as x64 depending on which flavor of Outlook you want to support.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 22, 2018 3:54 PM

  • Yes, the "AnyCPU" build of the application was the problem. Due to which it was running under x64 process on the 64-bit OS and causing the issue.

    Friday, March 23, 2018 12:32 PM