AppDomain.CreateDomain(String) Method
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.
Caution
Creating and unloading AppDomains is not supported and throws an exception.
Creates a new application domain with the specified name.
public:
static AppDomain ^ CreateDomain(System::String ^ friendlyName);
[System.Obsolete("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId="SYSLIB0024", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static AppDomain CreateDomain(string friendlyName);
public static AppDomain CreateDomain(string friendlyName);
[<System.Obsolete("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId="SYSLIB0024", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member CreateDomain : string -> AppDomain
static member CreateDomain : string -> AppDomain
Public Shared Function CreateDomain (friendlyName As String) As AppDomain
Parameters
- friendlyName
- String
The friendly name of the domain.
Returns
The newly created application domain.
- Attributes
Exceptions
friendlyName is null.
.NET Core and .NET 5+ only: In all cases.
Examples
The following sample demonstrates, in general, how to create a domain using one of the CreateDomain overloads.
// Set up the AppDomainSetup
AppDomainSetup^ setup = gcnew AppDomainSetup;
setup->ApplicationBase = "(some directory)";
setup->ConfigurationFile = "(some file)";
// Set up the Evidence
Evidence^ baseEvidence = AppDomain::CurrentDomain->Evidence;
Evidence^ evidence = gcnew Evidence( baseEvidence );
evidence->AddAssembly( "(some assembly)" );
evidence->AddHost( "(some host)" );
// Create the AppDomain
AppDomain^ newDomain = AppDomain::CreateDomain( "newDomain", evidence, setup );
// Set up the AppDomainSetup
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = "(some directory)";
setup.ConfigurationFile = "(some file)";
// Set up the Evidence
Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
Evidence evidence = new Evidence(baseEvidence);
evidence.AddAssembly("(some assembly)");
evidence.AddHost("(some host)");
// Create the AppDomain
AppDomain newDomain = AppDomain.CreateDomain("newDomain", evidence, setup);
open System
open System.Security.Policy
// Set up the AppDomainSetup
let setup = AppDomainSetup()
setup.ApplicationBase <- "(some directory)"
setup.ConfigurationFile <- "(some file)"
// Set up the Evidence
let baseEvidence = AppDomain.CurrentDomain.Evidence
let evidence = Evidence baseEvidence
evidence.AddAssembly "(some assembly)"
evidence.AddHost "(some host)"
// Create the AppDomain
let newDomain = AppDomain.CreateDomain("newDomain", evidence, setup)
' Set up the AppDomainSetup
Dim setup As New AppDomainSetup()
setup.ApplicationBase = "(some directory)"
setup.ConfigurationFile = "(some file)"
' Set up the Evidence
Dim baseEvidence As Evidence = AppDomain.CurrentDomain.Evidence
Dim evidence As New Evidence(baseEvidence)
evidence.AddAssembly("(some assembly)")
evidence.AddHost("(some host)")
' Create the AppDomain
Dim newDomain As AppDomain = AppDomain.CreateDomain("newDomain", evidence, setup)
Remarks
The friendlyName parameter is intended to identify the domain in a manner that is meaningful to humans. This string should be suitable for display in user interfaces.
This method overload uses the AppDomainSetup information from the default application domain.