0
votes

I have an Outlook add-in and it works fine. But, on the Outlook loading, my add-in shuts down and i got an error

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

There is the code of my Addin load

    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://stackguides.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");
        }
    }

As I wrote in my code, I commented out the Outlook processes count based on this

Uncommenting it will cause another error

Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

After my Outlook loaded, I enable my add-in through the menu and it works wonderful.

So, how can i resolve the loading issue?

Thanks guys

1

1 Answers

1
votes

Do not create a new instance of the Outlook.Application object (it will be crippled by the security patch anyway) - you get that object for free: use Globals.ThisAddIn.Application.