vsto - Outlook VSTO 加载项 - 加载错误 80080005
问题描述
我有一个 Outlook 加载项,它工作正常。但是,在 Outlook 加载时,我的加载项关闭并且出现错误
由于以下错误,检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005 服务器执行失败(来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))。
有我的插件加载的代码
Explorer thisExplorer;
public static Outlook.Application application;
Logger _logger = LogManager.GetCurrentClassLogger();
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
if (AppConfig.LoadConfigurations())
{
string nlogConfigFile = AppConfig.GetConfig<string>("NLogConfig");
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(nlogConfigFile, true);
_logger.Info("***************************NEW SESSION*******************************");
//https://stackoverflow.com/questions/46487050/c-sharp-get-running-outlook-instance-in-vsto-add-in
application = new Outlook.Application();
/*
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
int collCount = processes.Length;
if (collCount != 0)
{
// Outlook already running, hook into the Outlook instance
application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
}
else
{
application = new Outlook.Application();
}
*/
thisExplorer = Application.ActiveExplorer();
thisExplorer.SelectionChange += new ExplorerEvents_10_SelectionChangeEventHandler(ApplicationExplorer_SelectionChanged);
}
else
{
MessageBox.Show("Failed to load configurations");
}
}
正如我在代码中所写,我根据此注释了 Outlook 进程计数
取消注释将导致另一个错误
操作不可用(HRESULT 异常:0x800401E3 (MK_E_UNAVAILABLE))
加载 Outlook 后,我通过菜单启用我的加载项,它运行良好。
那么,我该如何解决加载问题?
多谢你们
解决方案
不要创建Outlook.Application
对象的新实例(无论如何它都会被安全补丁削弱) - 您可以免费获得该对象:使用Globals.ThisAddIn.Application
.
推荐阅读
- json - 将 numpy 数组添加到 pandas 数据帧
- php - 如何合并两个不同形式的输入
- c - Copy-Program 适用于小文件,对较大的文件产生分段错误
- c# - 将 Html.DisplayNameFor 与 IEnumerable 一起使用
- amazon-web-services - 从负载均衡器到 API 网关的请求?
- sql - 将多个值映射到一列
- php - php - 位掩码“解码”
- unit-testing - 笑话单元测试:阻止所有传出流量
- windows - 如何更改 Electron Builder 创建的应用程序快捷方式中的“开始”路径?
- sql-server - 使用隐藏表达式仅在 Tablix 中显示一行