调用 RibbonID Microsoft.Outlook.Explorer 的 GetCustomUI() 失败

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

我开发了一个 Outlook 2010 加载项,它可以在 Visual Studio (2010) 中打开项目的任何机器上完美运行,但是在所有其他计算机上都失败,并显示错误消息:

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

这告诉我对 IRibbonExtensibility 接口方法的调用失败了。这是一个运行时错误,但我不知道它是如何发生的或为什么会发生。

"same" 加载项以前与 Ribbon Designer 类 一起使用,现在已更改为使用 Ribbon XML 以支持加载项的一些添加的上下文菜单功能.

错误的影响是,尽管加载项 "active" 并已加载到 Outlook 中,但会显示 none 的按钮等,因为错误发生在任何 XML 可以显示色带设计

在我发现的各种故障排除文章中,有很多关于可能出错的建议,其中之一是我编写的代码可能与 Outlook 2007 相匹配,但不适用于 2010,但我确实这样做不知道潜在的差异在哪里。

以下是加载项结构中不同位置的一些代码:

在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

在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;
}

而我的 XML 返回 "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>

很抱歉与您分享这么多代码,但是重现这个问题似乎是一项徒劳的任务,而且由于扩展功能完全破坏了插件,我作为插件面临着时间压力, 不能被我工作场所的各种实体使用。

提前感谢任何可以提供有关可能错误的见解的人!特别是为什么它适用于涉及开发的机器而不是其他机器......

确保功能区XML 已作为嵌入式资源添加到您的项目中。我经常看到这个小细节被忽略导致 运行 在开发人员机器上没有问题但在客户端用户机器上失败。

如果这已经正确完成(您的文字没有详细说明),唯一的选择就是剥离。该问题可能是您的 RibbonXML 定义或读取 RibbonXML 文件的一部分。只需从一个非常简单的 XML、一个按钮定义开始,看看它是否适用于您的机器和客户端最终用户的机器。与 GetCustomUI 相同,将其限制为一行并检查结果。从那里开始扩展,直到找到失败的来源。

我发现了问题。 声明:

Debug.WriteLine(ribbonId);

使整个应用程序在客户端机器上崩溃,但在开发机器上(已打开项目的机器 Visual Studio)没有。

有人知道这是怎么回事吗? Debug.WriteLines 的全部目的不就是它只在调试期间有效吗?它不应该在发布项目后对 VSTO 造成问题...这是一个荒谬且很难发现的错误,因为它对我来说没有任何意义。

感谢@Maarten van Stam 的回复。