0

我有一个相当大的前景加载项,其中包含以下内容ribbon.xml:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabMail">
    <group id="groupViewHome" label="View tasks">
      <toggleButton id="buttonToggleHistoryHome" getLabel="getLabelToggleHistory" imageMso="ControlToggleButton" onAction="toggleHistory_Click" size="large" getPressed="getEnabledToggleHistory" />
    </group>
      </tab>
      <tab idMso="TabAddIns" label="DCP">
    <group id="groupCreateTask" label="Create a task">
      <button id="buttonNewTask" label="New Task" imageMso="QueryAppend" onAction="buttonNewTask_Click" size="large" getEnabled="getMailSelected" />
    </group>
    <group id="groupEdit" label="Edit a task">
      <button id="buttonAddSelection" label="Copy selection to task" imageMso="QueryUpdate" onAction="selectedText_Click" size="large" getEnabled="getMailAndIDSelected"/>
    </group>
    <group id="groupView" label="View tasks">
      <button id="buttonTaskHistory" imageMso="FileDocumentInspect" onAction="taskInfo_Click" getLabel="getButtonHistoryLabel" />
      <toggleButton id="buttonToggleHistory" getLabel="getLabelToggleHistory" imageMso="ControlToggleButton" onAction="toggleHistory_Click" getPressed="getEnabledToggleHistory" />
      <checkBox id="buttonTriggerMail" label="Toggle auto-history" onAction="Trigger_Click" getPressed="getInitialTriggerState"/>
    </group>
    <group id="groupAttach" label="Attachments">
      <button id="saveMail2" label="Add mail as .msg attachment" imageMso="AttachItem" onAction="saveMail_Click" getEnabled="getMailAndIDSelected"/>
      <button id="selectAttach" label="Select attachments to add" imageMso="AttachMenu" onAction="selectAttach_Click" getEnabled="getMailAndIDSelectedAndAttach"/>
    </group>
    <group id="groupLinks" label="Hyperlinks">
      <button id="addLinkToMail" label="Add task link to mail body" imageMso="HyperlinkInsert" onAction="addLink_Click" size="large" getEnabled="getMailAndIDSelected"/>
    </group>
      </tab>
    </tabs>
  </ribbon>
  <contextMenus>
    <contextMenu idMso="ContextMenuReadOnlyMailText">
      <menu id="dcp" label="DCP">
    <button id="selectedText" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click"/>
    <button id="addTask" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailTable">
      <menu id="dcp3" label="DCP">
    <button id="selectedText2" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click"/>
    <button id="addTask3" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailTableCell">
      <menu id="dcp4" label="DCP">
    <button id="selectedText3" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click"/>
    <button id="addTask4" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailListTable">
      <menu id="dcp5" label="DCP">
    <button id="selectedText4" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click"/>
    <button id="addTask5" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailPictureTable">
      <menu id="dcp6" label="DCP">
    <button id="selectedText5" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click" />
    <button id="addTask6" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailTextTable">
      <menu id="dcp7" label="DCP">
    <button id="selectedText6" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click"/>
    <button id="addTask7" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailTableWhole">
      <menu id="dcp8" label="DCP">
    <button id="selectedText7" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click" />
    <button id="addTask8" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailList">
      <menu id="dcp9" label="DCP">
    <button id="selectedText8" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click" />
    <button id="addTask9" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuReadOnlyMailHyperlink">
      <menu id="dcp10" label="DCP">
    <button id="selectedText9" label="Copy selection to task" imageMso="CitationInsert" onAction="selectedText_Click" />
    <button id="addTask10" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuMailItem">
      <menu id="dcp2" label="DCP">
    <button id="buttonTaskHistoryMail" label="View task history" imageMso="SourceControlShowHistory" onAction="taskInfo_Click" />
    <button id="addTask2" label="New task" imageMso="GoToNewRecord" onAction="buttonNewTask_Click" />
    <button id="saveMail" label="Add mail as .msg attachment" imageMso="AttachItem" onAction="saveMail_Click" />
      </menu>
    </contextMenu>
    <contextMenu idMso="ContextMenuAttachments">
    <button id="buttonAddAttachment" label="Add attachment to task" imageMso="AttachMenu" onAction="addAttachment_Click"/>
    </contextMenu>
  </contextMenus>
</customUI>

如您所见,我有几个需要失效才能启用的操作,切换...我的按钮。我的加载项启动良好,但在某些情况下会崩溃。以下是加载项几乎总是崩溃的一些示例:

  • 在新的检查器窗口中打开邮件项目并再次关闭它
  • 打开多个窗口,打开带有自定义按钮的上下文菜单

它发生的情况让我非常确定它与创建新上下文菜单或功能区时的自动失效有关,而不是当我自己调用它时。当我删除 getEnabled、getPressed... 属性时,错误不会持续存在。我想不出一种方法来抑制错误而不是崩溃或如何修复它。因此,如果有人可以提供帮助或可以给我更多关于这方面的信息,将不胜感激。如果您需要更多代码(例如 getEnabled、getPressed... 方法),请告诉我。

我的无效方法。请注意,大多数只是返回一个布尔值。这些布尔值作为私有变量保存在ribbon.cs 类中

public bool getEnabledToggleHistory(IRibbonControl control)
{
   return toggleHistoryPanelState;
}

public bool getMailSelected(IRibbonControl control)
{
    try
    {
        MailItem mailItem = getMail();
        if (mailItem != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch (System.Exception ex)
    {
        return false;
    }
}

public bool getMailAndIDSelected(IRibbonControl control)
{
    return mailAndIDSelected;
}

public bool getMailAndIDSelectedAndAttach(IRibbonControl control)
{
    if (hasAttachments && mailAndIDSelected)
    {
        return true;
    }
    return false;
}

如果我在新的 Visual Studio 实例中调试,我会得到以下信息:

Unhandled exception at 0x70B5B2A7 (MSO.DLL) in OUTLOOK.EXE: 0xC0000005: Access violation reading location 0x00000000.

如果我从我的解决方案中调试代码,我永远无法捕捉到错误,也不会说它有未处理的错误。它只是崩溃。

4

1 回答 1

0

(根据我们在评论中的讨论发布某种“答案”)

如果您无法捕获或记录(不要只是捕获异常,将某些内容放入转储中 - 您可以转储到临时用户文件夹中)...

我最好的建议the good old divide and conquer- 删除所有内容(你已经说过只有“标志”导致它),只需留下一个按钮,里面有一件事 - “返回”所有方法,直到你得到一个导致所有问题的方法- 类似的事情。

(用于功能区等的 OL XML 系统非常容易出错 - 因此您需要检查所有内容(一丝不苟) - 并且 OL 错误描述性不是很强,大多数情况下只是崩溃。顺便说一句,如果您删除整个上下文会发生什么-菜单?)

于 2013-03-25T14:46:13.093 回答