ApplicationActivator Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides the base class for the activation of manifest-based assemblies.
public ref class ApplicationActivator
[System.Runtime.InteropServices.ComVisible(true)]
public class ApplicationActivator
[<System.Runtime.InteropServices.ComVisible(true)>]
type ApplicationActivator = class
Public Class ApplicationActivator
- Inheritance
-
ApplicationActivator
- Attributes
Examples
The following code example shows how to obtain an ApplicationActivator object from the current DomainManager for a manifest-based application.
using System;
using System.Collections;
using System.Text;
using System.Security.Policy;
using System.Reflection;
using System.Security;
using System.Runtime.Hosting;
namespace ActivationContextSample
{
public class Program : MarshalByRefObject
{
public static void Main(string[] args)
{
// Get the AppDomainManager from the current domain.
AppDomainManager domainMgr = AppDomain.CurrentDomain.DomainManager;
// Get the ApplicationActivator from the AppDomainManager.
ApplicationActivator appActivator = domainMgr.ApplicationActivator;
Console.WriteLine("Assembly qualified name from the application activator.");
Console.WriteLine(appActivator.GetType().AssemblyQualifiedName);
// Get the ActivationArguments from the SetupInformation property of the domain.
ActivationArguments activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
// Get the ActivationContext from the ActivationArguments.
ActivationContext actContext = activationArgs.ActivationContext;
Console.WriteLine("The ActivationContext.Form property value is: " +
activationArgs.ActivationContext.Form);
Console.Read();
}
public void Run()
{
Main(new string[] { });
Console.ReadLine();
}
}
}
Imports System.Collections
Imports System.Text
Imports System.Security.Policy
Imports System.Reflection
Imports System.Security
Imports System.Security.Permissions
Imports System.Runtime.Hosting
Public Class Program
Inherits MarshalByRefObject
<SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy:=True)> _
Public Shared Sub Main(ByVal args() As String)
' Get the AppDomainManager from the current domain.
Dim domainMgr As AppDomainManager = AppDomain.CurrentDomain.DomainManager
' Get the ApplicationActivator from the AppDomainManager.
Dim appActivator As ApplicationActivator = domainMgr.ApplicationActivator
Console.WriteLine("Assembly qualified name from the application activator.")
Console.WriteLine(appActivator.GetType().AssemblyQualifiedName)
Dim ac As ActivationContext = AppDomain.CurrentDomain.ActivationContext
' Get the ActivationArguments from the SetupInformation property of the domain.
Dim activationArgs As ActivationArguments = AppDomain.CurrentDomain.SetupInformation.ActivationArguments
' Get the ActivationContext from the ActivationArguments.
Dim actContext As ActivationContext = activationArgs.ActivationContext
Console.WriteLine("The ActivationContext.Form property value is: " + _
activationArgs.ActivationContext.Form.ToString())
Console.Read()
End Sub
<SecurityPermission(SecurityAction.LinkDemand, ControlDomainPolicy:=True)> _
Public Sub Run()
Main(New String() {})
Console.ReadLine()
End Sub
End Class
Remarks
There is a single designated instance of the ApplicationActivator class in each AppDomain to which all activation calls are routed. The AppDomainManager for the current AppDomain can provide its own custom ApplicationActivator for this purpose. If a custom ApplicationActivator is not provided, an instance of the default ApplicationActivator is created.
The following steps describe the behavior of the default CreateInstance method implementation:
Checks if the ActivationContext of the add-in to be activated matches the ActivationContext of the current domain; if not, proceeds to step 2. Otherwise, executes the assembly and returns the result wrapped in an object handle.
Activates the add-in in a new AppDomain. The following steps are taken to initialize a new AppDomain using the ActivationArguments for the add-in.
Creates a new AppDomainSetup object using an ActivationArguments object containing the activation context for the add-in.
Calls the CreateInstanceHelper method to create a new domain using the AppDomainSetup object.
The CreateInstanceHelper method calls the HostSecurityManager.DetermineApplicationTrust method to acquire an ApplicationTrust object for the add-in. If the IsApplicationTrustedToRun property returns
true
, the add-in is executed. If not, CreateInstanceHelper throws a PolicyException indicating that execution permission could not be acquired.If the add-in is trusted to run, then a new AppDomain is created and configured for the ActivationContext of the add-in, and the add-in is loaded and executed.
The result of the activation of the add-in is returned, wrapped in an object handle.
A custom activator can tailor the activation of an add-in to a particular set of circumstances. For example, a custom activator could find an existing AppDomain to activate this add-in instead of creating a new domain every time.
The following steps describe the behavior of a custom ApplicationActivator that activates an add-in in an existing AppDomain:
The custom activator finds a domain that has the same ActivationContext as the add-in that is being activated.
If the ActivationContext has never been seen before in the process, the custom activator creates a new AppDomain for this ActivationContext by calling the CreateDomain method directly, or delegating this activity to the CreateInstanceHelper in the base class.
If there is an existing domain with the same ActivationContext, then the activator can delegate the CreateInstance method call to the ApplicationActivator in the target domain. Note that this would be a cross-domain call to an ApplicationActivator that resides in the target AppDomain.
Constructors
ApplicationActivator() |
Initializes a new instance of the ApplicationActivator class. |
Methods
CreateInstance(ActivationContext, String[]) |
Creates an instance of the application to be activated, using the specified activation context and custom activation data. |
CreateInstance(ActivationContext) |
Creates an instance of the application to be activated, using the specified activation context. |
CreateInstanceHelper(AppDomainSetup) |
Creates an instance of an application using the specified AppDomainSetup object. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |