This documentation is archived and is not being maintained.

How to: Activate Add-ins with Different Isolation and Security Levels

You can activate an add-in by using different application domain and process configurations to suit your isolation and security requirements. The Activate method overloads of the AddInToken class provide the following choices for activating an add-in:

  • In its own application domain, which is automatically generated by the system.

  • In an existing application domain, with or without other add-ins.

  • In the same environment (application domain and process) as another add-in.

  • In a new, external process that is separate from the host's process. The new process can include other add-ins that share that process.

When you activate an add-in in a new application domain or process, you must specify a security level by using either an AddInSecurityLevel or a PermissionSet object. For more information about activating add-ins, see Add-in Activation.

The following procedures show how to implement these activation options by using the Activate method overloads. The examples assume that the pipeline segment and add-in caches have been built, and that one or more add-ins have been found and returned in an AddInToken collection named tokens. For more information about how to build the cache files and find add-ins, see Add-in Discovery.

To activate an add-in in a new application domain

  • Use the Activate<T>(AddInSecurityLevel) or Activate<T>(PermissionSet) method overload.

    //Ask the user which add-in they would like to use.
    AddInToken selectedToken = ChooseAddIn(tokens);
    //Activate the selected AddInToken in a new
    //application domain with the Internet trust level.
    Calculator CalcAddIn = selectedToken.Activate<Calculator>(AddInSecurityLevel.Internet);
    //Run the add-in using a custom method.

To activate an add-in in the same application domain as another add-in

  • Use the Activate<T>(AppDomain) method overload.

    // Get the application domain
    // of an existing add-in (CalcAddIn).
    AddInController aiCtrl = AddInController.GetAddInController(CalcAddIn);
    AppDomain AddInAppDom = aiCtrl.AppDomain;
    // Activate another add-in in the same application domain.
    Calculator CalcAddIn3 =
    // Show that CalcAddIn3 was loaded
    // into CalcAddIn's application domain.
    AddInController aic = AddInController.GetAddInController(CalcAddIn3);
    Console.WriteLine("Add-in loaded into existing application domain: {0}",

To activate an add-in in the same application domain and process as another add-in

  • Use the Activate<T>(AddInEnvironment) method overload.

    // Get the AddInController of a 
    // currently actived add-in (CalcAddIn).
    AddInController aiController = AddInController.GetAddInController(CalcAddIn);
    // Select another token.
    AddInToken selectedToken2 = ChooseAddIn(tokens);
    // Activate a second add-in, CalcAddIn2, in the same
    // appliation domain and process as the first add-in by passing
    // the first add-in's AddInEnvironment object to the Activate method.
    AddInEnvironment aiEnvironment = aiController.AddInEnvironment;
    Calculator CalcAddIn2 =
    // Get the AddInController for the second add-in to compare environments.
    AddInController aiController2 = AddInController.GetAddInController(CalcAddIn2);
    Console.WriteLine("Add-ins in same application domain: {0}", aiController.AppDomain.Equals(aiController2.AppDomain));
    Console.WriteLine("Add-ins in same process: {0}", aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process));

To activate an add-in in a new process

  • Use the Activate<T>(AddInProcess, AddInSecurityLevel) or Activate<T>(AddInProcess, PermissionSet) method overload.

    // Create an external process.
    AddInProcess pExternal = new AddInProcess();
    // Activate an add-in in the external process
    // with a full trust security level.
    Calculator CalcAddIn4 =
    // Show that the add-in is an an external process
    // by verifying that it is not in the current (host's) process.
    AddInController AddinCtl = AddInController.GetAddInController(CalcAddIn4);
    Console.WriteLine("Add-in in host's process: {0}",