发布版本(已安装)中不显示 Outlook VSTO 窗体

Outlook VSTO form does not display in release version (installed)

感谢观看。

我正在开发一个 Outlook 插件,其中包含一个弹出窗口 Form,在其中加载 browser 以允许用户通过第三方身份验证服务登录。

这在调试会话 运行 时效果很好:我在功能区中看到自定义选项卡,单击“登录”按钮,然后使用 .ShowDialog() 以模态形式弹出表单。

我使用的是 Outlook 2016。

问题

当我发布此 VSTO 然后将其安装到我的计算机上时,插件加载并且我可以在自定义功能区选项卡中看到“登录”按钮,但单击它没有任何反应。我已经检查以确保对话框不会简单地在主窗体下弹出。如果它在那里--我找不到它。

返回调试会话——一切正常。我怀疑是权限问题,但我没有从 Outlook 收到任何提示或错误。

最后,我不知道是否相关,但我将 VSTO 安装程序发送给同事,他们在尝试安装时出现以下错误:

System.Security.SecurityException: Customized functionality in this application will not work because the certificate used to sign the deployment manifest for {APP NAME REMOVED} or its location is not trusted. Contact your administrator for further assistance.

非常感谢任何帮助。

很可能您的表单显示在 Outlook 后面 window。如果您希望始终在 Outlook windows 之上查看表单,则需要指定父 window 句柄。 ShowShowDialog methods of the System.Windows.Forms.Form class allows to specify the parent window handle by passing an instance of the IWin32Window 接口作为参数。

首先,您需要一个 class 来实现该接口:

public class WindowWrapper : System.Windows.Forms.IWin32Window
{
   public WindowWrapper(IntPtr handle)
   {
       _hwnd = handle;
   }

   public IntPtr Handle
   {
       get 
       { 
          return _hwnd; 
       }
   }

   private IntPtr _hwnd;
}

在 Outlook 中,您可以将 ExplorerInspector class 的实例转换为 IOleWindow 接口并获取 window 句柄,它可以是用于 IWin32Window 实施。