VSTO Add-In : Load Error [Outlook and other Office Applications]

A common issue faced by VSTO Add-in developers is the failure to load the add-in when your Office application starts. For example, the following message appears in COM Add-in window of Outlook 2003 if it is unable to load your add-in:

“Not Loaded. A runtime error occurred during the loading of the COM Add-in”

There can be many reasons for this behavior and requires your step by step verification of each one. Note that the message descriptions given below are specific for Outlook 2003 and Outlook 2007 and may vary for other office applications.

1. Enable the Add-in (if it is found under disabled items)

Outlook 2003:

  • Go to Help –> About Microsoft Office
  • Click on “Disabled Items”
  • Select your add-in (if found there) and click enable
  • Close and start Outlook

Outlook 2007:

Use the following steps to access Disabled items:

  • Go to Help—> Disabled Items

OR

  • On the Tools menu, click Trust Center.
  • In the Navigation Pane, click Add-ins.
  • In the Manage list, select Disabled Items, and then click Go.

2. Enable the Add-in from  COM Add-in Window

Outlook 2003:

  • Go to Tools –> Options –> Others –> Advanced Options –> COM Add-ins
  • Select and Check your add-in (if found there as unchecked) and click OK
  • Your outlook plug-in should load now, if not go back to COM Add-ins window and see if there are any error messages.

Outlook 2007:

Use the following steps to access Disabled items:

  • On the Tools menu, click Trust Center.
  • In the Navigation Pane, click Add-ins.
  • In the Manage list, select COM Add-ins, and then click Go.
  • Select and Check your add-in (if found there as unchecked) and click OK

3. Check registry settings

  • Go to : HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Outlook\Addins\<AddIn Name> (Or HKCU equivalent)
  • Check the loadbehavior key value. If it is set to 2, change to 3 and start your Outlook
  • If the Add-in does not load, go back to registry and check the loadbehavior value. You may notice that the value is changed back to 2 (indicating the problem while loading your plug-in) and we should go to next steps.

4. Check CAS (Code Access Security) permissions for the code group

Your Add-in assemblies code group should be given “FullTrust” permission. You can verify the current permission levels using one of the following.

  • CASPOL.EXE : Use caspol tool to query the code groups and permission levels
  • Use .NET Framework Configuration Tool (mscorcfg.msc)

If FullTrust permissions are not given, use caspol.exe to grant FullTrust to the add-in assemblies

Example: <From Visual Studio Command Prompt>

caspol -u -ag All_Code –url  “C:\<FolderName>\<FolderName>\*” FullTrust -n "<Name>" –d "<Description>"

More details on CAS is out of scope for this post. You can refer this for detailed instructions: How to: Grant Permissions to Folders and Assemblies

5. Check Primary Interop Assemblies (PIA) are installed correct

Verify whether Primary Interop Assemblies [for Office 2003 or Office 2007 depending upon your version of MS Office] installed correctly on your machine. To check this, go to GAC (%systemroot%\assembly) and look for assemblies named Microsoft.Office.Interop.*  and their versions.

If not installed, get it downloaded from the following URLs:

6. Add Custom Logging

Place the code in the Startup event to log exception details to  System Event Log which can give you if the exceptions are occurred during the load event.

<To be updated>

The above steps will help to identify/fix the load error. If you do not find the solution for your error get more help from this Microsoft Support Link to troubleshoot.

Advertisements

Add-in development for Microsoft Office

It is quite likely that many of you get requirements to extend the MS Office applications’ capabilities based  on your business needs.  Well, we are talking about the .NET development and the framework provides you capabilities for developing Office based solutions using Visual Studio Tools for Office.

This portal (Office Development with Visual Studio) provides many resources related to Office Solutions development using .NET framework including Add-In development for MS Office 2003 and Office 2007 

How does Add-Ins work with MS Word, Excel etc?

Add-ins that are created by using Visual Studio Tools for Office consist of an assembly that is loaded into a Microsoft Office application as an add-in. Add-ins that are created by using Visual Studio Tools for Office have access to the Microsoft .NET Framework as well as the application’s object model. When you build an add-in project, Visual Studio compiles the assembly into a .dll file and creates a separate application manifest file. The application manifest points to the assembly, or to the deployment manifest if the solution uses one.

Visual Studio Tools for Office provides a loader for add-ins that are created by using Visual Studio Tools for Office. This loader is named AddinLoader.dll. When a user starts the Microsoft Office application, this loader starts the common language runtime (CLR) and the Visual Studio Tools for Office runtime, and then loads the add-in assembly. The assembly can capture events that are raised in the application.

The CLR enables the use of managed code that is written in a language supported by the Microsoft .NET Framework. In your solution, you can do the following:

  • Respond to events that are raised in the application itself (for instance, when a user clicks a menu item).
  • Write code against the object model to automate the application.

After the assembly has been loaded, the add-in has access to the application’s objects, such as documents or mail. The managed code communicates with the application’s COM components through the primary interop assembly in your add-in project.