This documentation is archived and is not being maintained.

AddInToken Class

Represents an add-in that can be activated.

Namespace:  System.AddIn.Hosting
Assembly:  System.AddIn (in System.AddIn.dll)

public sealed class AddInToken : IEnumerable<QualificationDataItem>, 

An AddInToken object represents an add-in, and its associated pipeline segments, that can be activated. The token contains the name, assembly name, description, publisher, and version of the add-in that it represents.

Use the AddInStore.FindAddIns method to get a collection of tokens that represent add-ins whose pipelines match a specified host view. Use the AddInStore.FindAddIn method to get a collection of tokens that represent all the pipelines for a specified add-in that match a specified host view.

To activate an add-in, pass the token that represents the desired add-in to the Activate method. This method returns an instance of the type that represents the host view of the add-in.

The Activate method has several overloads. When you use an overload that does not require the name of an application domain as one of its parameters, a new application domain for the add-in is automatically created.

You can use Language-Integrated Query (LINQ) extension methods to perform queries on an AddInToken, treating the token as a collection of QualificationDataItem structures.

This section contains two examples. The first example activates an add-in that has been selected by using the ChooseAddIn method, and the second example shows the ChooseAddIn method.

Example 1

The following example shows how to activate an add-in with a token.

//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.

Example 2

The following example shows the custom ChooseAddIn method, which enumerates an AddInToken collection. The user selects a token from this collection to activate the corresponding add-in.

// Method to select a token by  
// enumeratng the AddInToken collection. 
private static AddInToken ChooseAddIn(Collection<AddInToken> tokens)
    if (tokens.Count == 0)
        Console.WriteLine("No add-ins are available");
        return null;

    Console.WriteLine("Available add-ins: ");

	// Show the token properties for each token  
	// in the AddInToken collection (tokens), 
	// preceded by the add-in number in [] brackets. 
    int tokNumber = 1;
	foreach (AddInToken tok in tokens)
		Console.WriteLine(String.Format("\t[{0}]: {1} - {2}\n\t{3}\n\t\t {4}\n\t\t {5} - {6}",

    Console.WriteLine("Which calculator do you want to use?");
    String line = Console.ReadLine();
    int selection;
    if (Int32.TryParse(line, out selection))
        if (selection <= tokens.Count)
            return tokens[selection - 1];
    Console.WriteLine("Invalid selection: {0}. Please choose again.", line);
    return ChooseAddIn(tokens);


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5