首页 文章

通过Word或Excel上的“发送邮件”选项启动Outlook启动时Outlook 2007 Addin启动崩溃

提问于
浏览
1

在我的新工作中开始使用Outlook 2007 Addin进行开发后,用户在Outlook启动期间遇到以下错误: Object reference not set to an instance of an object . 尝试通过额外的尝试捕获来跟踪问题,因为来自未抑制的警报的初始VSTO异常消息不是特别有用 . 我跟踪了以此代码开头的方法的问题:

if (newToolBar == null)
{
    Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars;
    newToolBar = cmdBars.Add("Data Team Toolbar", Office.MsoBarPosition.msoBarTop, false, true);
}

作为VSTO的新手,我的第一个假设是ActiveExplorer() . CommandBars返回null . 在与我的最终用户进一步通信之后,我能够确认他们已经使用Excel的邮件菜单中的发送邮件选项启动了Outlook . (这不是我预见过的场景 . )这似乎与我的主要Outlook窗口的理论不合作,并且我能够成功地重现崩溃 .

因此我添加了以下代码

if (this.Application.ActiveExplorer() == null )
{
    // If Outlook is opened via some other method ie. send on Excel or Word
    // Kill Addin nicely.
    this.OnShutdown();
}

但是,我很快意识到我在UAT下发布这个版本(因为我似乎无法找到在Visual Studio中重现问题的方法(命令开关(https://support.office.com/en-sg/article/Command-line-switches-for-Microsoft-Office-Outlook-2007-92de9e0b-4f97-42a2-8e02-89c4a8294916))具体"/c ipm.note"设置为调试参数似乎对调试启动过程没有影响 .

根据这个链接(VSTO Outlook integration - Outlook shutdown event for synchronization),这似乎关闭Outlook,而不仅仅是我想到的Addin .

我从设计预期(虽然不理想)中想到的唯一解决方案是禁止Addin在这种情况下采取进一步行动,但允许它在正常启动条件下再次运行而无需用户干预 . 我认为逻辑可以包含在这样的保护条款中,

if (this.Application.ActiveExplorer().Caption != "Microsoft Outlook")
{
    //Disabling code//
}

但是我不确定我是如何或者是否要实现这个,因为我的Addin在工具栏上有很多依赖(这个解决方案意味着需要添加许多非常具体的保护条款来检查存在的工具栏是否需要添加我宁愿避免,如果可能的话 . 理想情况下,我希望Addin能够检测它是否以不同的方式运行,如果以这种方式打开,只有当Outlook的主窗口可见时才加载工具栏,我已经有了一个背景主循环作为其他要求的一部分 . 所以可能是某些东西?

if(DataTeamAddin.LoadStyle != "Normal")
{
    if(OutlookMainWindowVisible == true && ToolbarIsNotLoaded == true)
    {
        BeginToolbarSetup();
    }
    else
    {
        //Resume Main Loop
    }
}

但是我不确定该怎么办呢?更不用说如何使用MSTest中的自动化测试对此进行测试,因为我甚至无法在VS2013 IDE中重现该问题?

2 回答

相关问题