1

I have a C# VSTO Outlook (2016) Add-in published as load on demand. The Add-in create a custom ribbon button when creating a new appointment. When I load Outlook and open a new appointment the ribbon button is not displayed. The Add-in is checked when I go to COM add-ins menu in the developer ribbon but the status is load on demand (not loaded at the moment). In the File -> Options -> Add-ins, it is listed in the inactive section. LoadBehavior is set to 9 in the registry which I believe is what it shoud be after the first time.

When I unchecked the Add-in in the COM Add-ins menu, click OK, re-open, the COM Add-ins menu and check the Add-in again, the custom ribbon button reappear correctly so the code is working properly. I set the add-in as load on demand otherwise it is always disable because of slow loading time despite having an empty ThisAddIn_Startup function. I assume it is because of the loading of the .net runtime as I have seen in other posts. Also, I don't need the add-in loaded at startup as I only need the button when creating a new appointment. If possible, I would prefer avoiding modifying the registry and set the loadbehavior to 3 to force outlook to load the add-in.

Any ideas on how I could achieve that?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Gryffins
  • 11
  • 1

1 Answers1

1

I set the add-in as load on demand otherwise it is always disable because of slow loading time despite having an empty ThisAddIn_Startup function. I assume it is because of the loading of the .net runtime as I have seen in other posts

Not always .net runtime. Your add-in instance must be created by the VSTO loader, so when an instance is created all dependent assemblies and components are loaded/created. You may re-think what dependencies are used in the add-in to decrease the required time for that. Note, you could initialize them at a later stage. For example, in case of Outlook, consider using the Application.Startup event which is fired when Microsoft Outlook is starting, but after all add-in programs have been loaded.

Also, I don't need the add-in loaded at startup as I only need the button when creating a new appointment.

Ribbon controls are requested by Office applications when the window is created and loaded. In that case it makes sense to have the add-in loaded at startup. The IRibbonExtensibility.GetCustomUI method is called by Office applications, typically it loads the XML markup, either from an XML customization file or from XML markup embedded in the procedure, that customizes the Ribbon user interface.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I thought the XML customization was cached with load on demand, isn't it? Also, how can you debug the load time from your Add-in? It's hard to find any documentation on that part. – Gryffins Jan 15 '23 at 14:08
  • When the limit is exceeded the time can be find in the windows event viewer. You can measure the time required for the startup event by using the [StopWatch](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch?view=net-7.0) class. See [Using Stopwatch in C#](https://stackoverflow.com/questions/55686928/using-stopwatch-in-c-sharp) – Eugene Astafiev Jan 28 '23 at 13:49