locked
FormRegionInitializing only fires when in Debug Mode (VSTO Outlook) RRS feed

  • Question

  • I have built an VSTO Outlook add-in which simply displays an adjoining form region in the reading pane when selecting a mail message (IPM.Note message class) from the object explorer. The add-in works as expected when in debug mode. However, when installed using a setup program, the add-in loads correctly (and the code fires a MessageBox.Show() on startup, but the Form Region does not display. I have placed MessageBox.Show() events in the RepInfoFactory_FormRegionInitializing method but none of them fire.

    I have searched for a similar situations but found only those in which the entire add-in was disabled. In my case it is loaded fine. I have tried starting Outlook as the administrator, but that does not seem to affect the add in. I have also set my environment variables to display VSTO alerts and log them but nothing is logged--I suspect because the add-in loads fine.

    Since I have the FormRegionMessageClass attribute set to Note I double-checked that the objects in the explorer are indeed IPM.Note.

    I am running Outlook 2016 (Click-to-Run) and VS 2019.

    I would love any other suggestions on things to check/try.

    Thanks!

    public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                MessageBox.Show("Addin Startup");  //this message box displays in both debug and installed version
            }
        }
    
    partial class RepInfo
        {
            public static Outlook.ExchangeUser contact;
            public static System.Data.DataTable dtRepHier;
            public static System.Data.DataTable dtSubHier;
            #region Form Region Factory 
    
            [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
            [Microsoft.Office.Tools.Outlook.FormRegionName("WATCHTOWER.RepInfo")]
            partial class RepInfoFactory
            {
                //The code in this method only works in debug mode.  The form only displays (under the stated conditions) when in debug mode.
                private void RepInfoFactory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
                {
                    //MessageBox.Show(e.FormRegionMode.ToString() + " " + e.FormRegionSize.ToString());
                    Outlook.MailItem myItem = (Outlook.MailItem)e.OutlookItem;
                    //MessageBox.Show(myItem.MessageClass);
                    if (myItem != null)
                        //MessageBox.Show(myItem.Sender.Name);
                        if (myItem.Sender != null)
                        {
                            {
                                contact = myItem.Sender.GetExchangeUser();
                            //MessageBox.Show(contact.Department);
                                if (contact != null && contact.Department != null && (contact.Department.Substring(7, 10) == "US-AVD-VAS"
                                    || contact.Department.Substring(7, 9) == "US-AVD-US"))
                                { return; }
                            }
    
                            e.Cancel = true;
                        }
                }
            }
    
            #endregion
    // code continues

    I reviewed the requirements for inserting registry entries for each message class, since the documentation from Microsoft (https: //docs.microsoft.com/en-us/visualstudio/vsto/registry-entries-for-vsto-add-ins?view=vs-2019) indicates this must be done through the Windows Installer configuration. I tried the following without any success:

    • The name of my registry key for the project is "Computer \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\Outlook\AddIns\COMPANY.CustSvc.Watchtower". As I understand it, this must be listed as part of the FormRegions registry entry.
    • The FormRegions\IPM.Note branch is "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\Outlook\AddIns\FormRegions\IPM.Note"
    • The entry for the IPM.Note is "WATCHTOWER. RepInfo" (this is the name of the FormRegionName attribute) and the value is "=COMPANY.CustSvc.Watchtower" (the name of the registry key).
    • I added logging but nothing is logged from the FormRegionInitializing event since it is not firing.

    Any other thoughts on why the FormRegionInitializing is not firing?





    • Edited by mrochek Monday, June 15, 2020 3:55 PM
    Monday, June 15, 2020 3:35 PM

All replies