首页 > 解决方案 > 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 后,我通过菜单启用我的加载项,它运行良好。

那么,我该如何解决加载问题?

多谢你们

标签: vstooutlook-addin

解决方案


不要创建Outlook.Application对象的新实例(无论如何它都会被安全补丁削弱) - 您可以免费获得该对象:使用Globals.ThisAddIn.Application.


推荐阅读