Search code examples
c#xmlvstooutlook-addinoutlook-2010

The call to GetCustomUI() for RibbonID Microsoft.Outlook.Explorer failed


I have developed an Outlook 2010 Add-in which works perfectly on any machine that has had the project opened in Visual Studio (2010), however which fails on all other computers, with the error message:

"The call to GetCustomUI() for RibbonID Microsoft.Outlook.Explorer failed"

This tells me that the very call to the IRibbonExtensibility interface method failed. It's a runtime error, however I have no idea how or why it is happening.

The "same" add-in worked previously with Ribbon Designer classes, and has now been changed to use Ribbon XML to support some added context menu features for the add-in.

The effect of the error is that, despite the add-in being "active" and loaded into Outlook, none of its buttons, etc. are shown, because the error occurs before any XML Ribbon design can be displayed.

In various troubleshooting articles I found, there were many suggestions for what could be wrong, and one of them is that perhaps the code I have written matches what fits Outlook 2007 and doesn't work for 2010, however I do not know where potential differences lie.

Here is some code from various places in the Add-in structure:

In MyOutlookAddIn.cs:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    return new Ribbon();
}

#region VSTO generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
    this.Startup += new System.EventHandler(ThisAddIn_Startup);
    this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion

In Ribbon.cs:

public string GetCustomUI(string ribbonId)
{
    Debug.WriteLine(ribbonId);
    //Return the appropriate Ribbon XML for ribbonID
    switch (ribbonId)
    {
        case "Microsoft.Outlook.Explorer":
            return GetResourceText("OutlookAddIn.RibbonDesignXML.Explorer.xml");
        case "Microsoft.Outlook.Mail.Read":
            return GetResourceText("OutlookAddIn.RibbonDesignXML.MailReadRibbon.xml");
        case "Microsoft.Outlook.Appointment.Read":
            return GetResourceText("OutlookAddIn.RibbonDesignXML.AppointmentReadRibbon.xml");
        default:
            return null;
    }
}

public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
    this.ribbon = ribbonUI;
}

And my XML returned for "Microsoft.Outlook.Explorer" ("OutlookAddIn.RibbonDesignXML.Explorer.xml"):

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <!-- Når en mail er valgt i kalender oversigten -->
    <tabs>
      <tab idMso="TabMail">
        <group id="groupTabMail" label="Jira">
          <button id="sendToJiraBtn" onAction="ExplorerSendToJiraButtonClicked" label="Send til Jira" getImage = "GetImage" size="large" />
          <button id="jiraSettingsBtn" onAction="ExplorerSettingsButtonClicked" label="Indstillinger" getImage="GetSettingsImage" size="large" />
          <button id="jiraSupportBtn" onAction="ExplorerSupportButtonClicked" label="Hjælp" getImage="GetSupportImage" size="large" />
        </group>
      </tab>
    </tabs>

    <!-- Når en aftale er valgt i kalender oversigten -->
    <contextualTabs>
      <tabSet idMso="TabSetAppointment">
        <tab idMso="TabAppointment">
          <group id="groupTabAppointment" label="Jira">
            <button id="sendToJiraBtnAppointment" onAction="ExplorerSendToJiraButtonClicked" label="Send til Jira" getImage = "GetImage" size="large" />
            <button id="jiraSettingsBtnAppointment" onAction="ExplorerSettingsButtonClicked" label="Indstillinger" getImage="GetSettingsImage" size="large" />
            <button id="jiraSupportBtnAppointment" onAction="ExplorerSupportButtonClicked" label="Hjælp" getImage="GetSupportImage" size="large" />
          </group>
        </tab>
      </tabSet>
      <tabSet idMso="TabSetReccurringAppointment">
        <tab idMso="TabRecurringAppointment">
          <group id="groupTabRecurringAppointment" label="Jira">
            <button id="sendToJiraBtnRecurringAppointment" onAction="ExplorerSendToJiraButtonClicked" label="Send til Jira" getImage = "GetImage" size="large" />
            <button id="jiraSettingsBtnRecurringAppointment" onAction="ExplorerSettingsButtonClicked" label="Indstillinger" getImage="GetSettingsImage" size="large" />
            <button id="jiraSupportBtnRecurringAppointment" onAction="ExplorerSupportButtonClicked" label="Hjælp" getImage="GetSupportImage" size="large" />
          </group>
        </tab>
      </tabSet>
    </contextualTabs>
  </ribbon>


  <contextMenus>
    <contextMenu idMso="ContextMenuMailItem">
      <menuSeparator id="MailSeparator"/>
      <button id="SendToJiraMailItem"
          getImage = "GetImage"
          label="Send til Jira"
          onAction="ExplorerSendToJiraButtonClicked"/>

      <dynamicMenu id="DynamicMenuMail" label= "Send til Jira som..." getImage="GetImage" getContent="GetContent" />
    </contextMenu>

    <contextMenu idMso="ContextMenuMultipleItems">
      <menuSeparator id="MultipleItemsSeparator"/>
      <button id="SendToJiraMultipleItems"
          getImage = "GetImage"
          label="Send til Jira"
          onAction="ExplorerSendToJiraButtonClicked"/>

      <dynamicMenu id="DynamicMenuMultiple" label= "Send til Jira som..." getImage="GetImage" getContent="GetContent" />
    </contextMenu>

    <contextMenu idMso="ContextMenuCalendarItem">
      <menuSeparator id="AppointmentSeparator"/>
      <button id="SendToJiraCalendarItem"
          getImage = "GetImage"
          label="Send til Jira"
          onAction="ExplorerSendToJiraButtonClicked"/>

      <dynamicMenu id="DynamicMenuAppointment" label= "Send til Jira som..." getImage="GetImage" getContent="GetContent" />
    </contextMenu>
  </contextMenus>
</customUI>

I'm sorry for sharing this amount of code with you, however reproducing the issue seems a futile task, and I am under time pressure as the Add-in, due to the extended features destroying the Add-in altogether, cannot be used by various entities at my workplace.

Thank you in advance to anyone who can bring insight as to what may be wrong! And especially why it works on development-involved machines and not others...


Solution

  • I found the problem. The statement:

    Debug.WriteLine(ribbonId);
    

    made the whole app crash on client machines, but not on development machines (machines that have had the project open i Visual Studio).

    Does anybody have any clue as to how this could be? Isn't the whole purpose of Debug.WriteLines that it only has an effect during debugging? It shouldn't be causing issues to VSTO after publishing the project... A ridiculous and quite difficult error to discover, as it doesn't really make any sense to me.

    Thanks for the reply, @Maarten van Stam.