AppDomainSetup.ApplicationName Property

Definition

Gets or sets the name of the application.

C#
public string ApplicationName { get; set; }

Property Value

The name of the application.

Implements

Examples

The following example shows how to set the ApplicationName property when you create a new application domain.

The example creates a new application domain, and then calls the AppDomain.CreateInstanceAndUnwrap method to load the example assembly into the new application domain and create an instance of the Worker class. The Worker class inherits MarshalByRefObject, so the example can use the proxy returned by CreateInstanceAndUnwrap to call the TestLoad method.

The TestLoad method loads an assembly that you specify. You must either specify a valid, fully qualified assembly name, or comment out the Load(String) method. The TestLoad method lists the assemblies that are loaded into the new application domain, showing that your specified assembly and the example assembly are loaded.

The example uses the LoaderOptimizationAttribute attribute to tell the assembly loader how the application will share code across application domains.

C#
using System;
using System.Reflection;
using System.Security.Policy;

class ADMultiDomain
{
   // The following attribute indicates to loader that multiple application
   // domains are used in this application.
   [LoaderOptimizationAttribute( LoaderOptimization.MultiDomainHost)]
   public static void Main()
   {
      // Create application domain setup information for new application domain.
      AppDomainSetup domaininfo = new AppDomainSetup();
      domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
      domaininfo.ApplicationName = "MyMultiDomain Application";

      //Create evidence for the new appdomain from evidence of current application domain.
      Evidence adevidence = AppDomain.CurrentDomain.Evidence;

      // Create appdomain.
      AppDomain newDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo);

      // Load an assembly into the new application domain.
      Worker w = (Worker) newDomain.CreateInstanceAndUnwrap(
         typeof(Worker).Assembly.GetName().Name,
         "Worker"
      );
      w.TestLoad();

      //Unload the application domain, which also unloads the assembly.
      AppDomain.Unload(newDomain);
   }
}

class Worker : MarshalByRefObject
{
   internal void TestLoad()
   {
      // You must supply a valid fully qualified assembly name here.
      Assembly.Load("Text assembly name, Culture, PublicKeyToken, Version");
      foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
         Console.WriteLine(assem.FullName);
   }
}

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1