How to Create Application Domain Using Framework 2.0

This article will describe the members used to create appdomain in runtime.

using System;

namespace AppdomainCreation_Console
{
      class Program
      {
            static void Main(string[] args)
            {

                    //Instantiate AppDomainSetup object
                    AppDomainSetup appDomainSetup = new AppDomainSetup();
                    //Configure AppDomainSetup Setup Information
                   
//Directory where CLR will look during probing to resolve private assemblies.
                   
//By default this is the directory containing the assembly.
                    appDomainSetup.ApplicationBase = @"c:\Test";

                    //Configuration name file used by code loaded into assembly.
                    //By default it is stored in the same folder as the assembly.
                   
//If we set applicationBase the n it should be in same folder.
                    appDomainSetup.ConfigurationFile = "AD.Config";

                    //Semicolon-seprated list of directories that the runtime uses when probing for
                    //private assemblies. these directories are relative to the directory specified
                    //in ApplicationBase.
                    appDomainSetup.PrivateBinPath = "bin;plugins;external";

                    //Remember to save a Reference to the new AppDomain as this Cannot be retrived any other way
                    AppDomain appDomain = AppDomain.CreateDomain("My First Domain", null, appDomainSetup);
                    Console.WriteLine("AppDomain Created, Press ENTER");
                    Console.ReadLine();
            }
     }
}

Up Next
    Ebook Download
    View all
    Learn
    View all