0
votes

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

UPDATE Based on the response from @Eugene below, I reviewed the requirements for inserting registry entries for each message class, since the documentation from Microsoft 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 per @Eugene's suggestion and nothing is logged from the FormRegionInitializing event since it is not firing.

Any other thoughts on why the FormRegionInitializing is not firing?

1

1 Answers

0
votes

First of all, I'd suggest adding any logging mechanisms to the code to see how the code works on the end-user machines and log exceptions if any takes place.

The MessageBox.Show method is not the right way for testing the code.

However, when installed using a setup program

The Microsoft.Office.Tools.Outlook namespace gives you access to classes that represent the form region, the Outlook item that displays the form region, and other useful items. The Outlook Form Region item automatically adds a reference to this assembly in the project and inserts the appropriate using or Imports statement at the top of the form region code file.

Form regions are deployed automatically with the associated Outlook VSTO Add-in. Therefore, you do not have to perform any special tasks to deploy a form region. For more information about deploying VSTO Add-ins, see Deploy an Office solution.

However, when you build an Outlook VSTO Add-in project that contains a form region, Visual Studio adds the following information to the registry:

  • A key for each message class that is associated with one or more form regions.

  • An entry for each form region and an associated value that represents the name of the Outlook VSTO Add-in.

Outlook uses this information to load the form regions.