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

时间:2016-02-25 09:19:23

标签: c# xml vsto outlook-addin outlook-2010

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

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

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

“相同”加载项以前使用Ribbon Designer类工作,现在已更改为使用功能区XML来支持加载项的一些添加的上下文菜单功能。

错误的结果是,尽管加载项处于“活动状态”并加载到Outlook中,但没有显示任何按钮等,因为错误发生在任何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>

我很抱歉与你共享这么多代码,但是重现这个问题似乎是徒劳的任务,而且由于扩展功能完全破坏加载项,我在时间压力下加载,不能被我工作场所的各种实体使用。

提前感谢任何能够洞察可能出错的人!特别是为什么它适用于涉及开发的机器而不是其他机器......

2 个答案:

答案 0 :(得分:1)

我发现了问题。 声明:

Debug.WriteLine(ribbonId);

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

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

感谢你回复@Maarten van Stam。

答案 1 :(得分:-1)

确保将RibbonXML作为嵌入资源添加到项目中。我经常看到这个小细节被省略,导致开发人员机器上没有问题但在客户端最终用户机器上运行失败。

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