c# Outlook插件setCurrentFormPage抛出异常



我正在开发一个插件outlookVSTO,我试图把一个单独的表单区域显示为当前的表单页面在打开的检查器,但抛出一个异常。下面是代码

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.Inspectors.NewInspector += InspectorsOnNewInspector;
        this.Application.Explorers.NewExplorer +=  Explorers_NewExplorer;
    }
    private void Explorers_NewExplorer(Outlook.Explorer explorer)
    {
    }
    private void InspectorsOnNewInspector(Outlook.Inspector inspector)
    {
        MessageBox.Show("ola");
        // exception ocurrs in this line 
        inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion");
    }
    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

我设法用下面的代码使它工作

 private void InspectorsOnNewInspector(Outlook.Inspector inspector)
    {
        MessageBox.Show("ola");
        if (!(inspector.CurrentItem is Outlook.TaskItem)) return;
        var taskItem = (Outlook.TaskItem) inspector.CurrentItem;
        taskItem.Open += (ref bool cancel) =>
        {
            try
            {
                inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        };
    }

最新更新