Modifier

Partager via


AppDomain.CreateDomain Method

Definition

Creates a new application domain.

Overloads

CreateDomain(String, Evidence, String, String, Boolean, AppDomainInitializer, String[])

Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain. Specifies a callback method that is invoked when the application domain is initialized, and an array of string arguments to pass the callback method.

CreateDomain(String, Evidence, String, String, Boolean)

Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain.

CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])

Creates a new application domain using the specified name, evidence, application domain setup information, default permission set, and array of fully trusted assemblies.

CreateDomain(String, Evidence)

Creates a new application domain with the given name using the supplied evidence.

CreateDomain(String)
Obsolete.

Creates a new application domain with the specified name.

CreateDomain(String, Evidence, AppDomainSetup)

Creates a new application domain using the specified name, evidence, and application domain setup information.

CreateDomain(String, Evidence, String, String, Boolean, AppDomainInitializer, String[])

Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain. Specifies a callback method that is invoked when the application domain is initialized, and an array of string arguments to pass the callback method.

public:
 static AppDomain ^ CreateDomain(System::String ^ friendlyName, System::Security::Policy::Evidence ^ securityInfo, System::String ^ appBasePath, System::String ^ appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer ^ adInit, cli::array <System::String ^> ^ adInitArgs);
public static AppDomain CreateDomain (string friendlyName, System.Security.Policy.Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs);
static member CreateDomain : string * System.Security.Policy.Evidence * string * string * bool * AppDomainInitializer * string[] -> AppDomain
Public Shared Function CreateDomain (friendlyName As String, securityInfo As Evidence, appBasePath As String, appRelativeSearchPath As String, shadowCopyFiles As Boolean, adInit As AppDomainInitializer, adInitArgs As String()) As AppDomain

Parameters

friendlyName
String

The friendly name of the domain. This friendly name can be displayed in user interfaces to identify the domain. For more information, see FriendlyName.

securityInfo
Evidence

Evidence that establishes the identity of the code that runs in the application domain. Pass null to use the evidence of the current application domain.

appBasePath
String

The base directory that the assembly resolver uses to probe for assemblies. For more information, see BaseDirectory.

appRelativeSearchPath
String

The path relative to the base directory where the assembly resolver should probe for private assemblies. For more information, see RelativeSearchPath.

shadowCopyFiles
Boolean

true to load a shadow copy of an assembly into the application domain.

adInit
AppDomainInitializer

An AppDomainInitializer delegate that represents a callback method to invoke when the new AppDomain object is initialized.

adInitArgs
String[]

An array of string arguments to be passed to the callback represented by adInit, when the new AppDomain object is initialized.

Returns

The newly created application domain.

Exceptions

friendlyName is null.

Remarks

The method represented by adInit is executed in the context of the newly created application domain.

If securityInfo is not supplied, the evidence from the current application domain is used.

For more information about shadow copying, see ShadowCopyFiles and Shadow Copying Assemblies.

Important

Do not use this method overload to create sandboxed application domains. Beginning with the .NET Framework 4, the evidence that is supplied for securityInfo no longer affects the grant set of the application domain. Use the CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload to create sandboxed application domains.

Applies to

CreateDomain(String, Evidence, String, String, Boolean)

Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain.

public:
 static AppDomain ^ CreateDomain(System::String ^ friendlyName, System::Security::Policy::Evidence ^ securityInfo, System::String ^ appBasePath, System::String ^ appRelativeSearchPath, bool shadowCopyFiles);
public static AppDomain CreateDomain (string friendlyName, System.Security.Policy.Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles);
static member CreateDomain : string * System.Security.Policy.Evidence * string * string * bool -> AppDomain
Public Shared Function CreateDomain (friendlyName As String, securityInfo As Evidence, appBasePath As String, appRelativeSearchPath As String, shadowCopyFiles As Boolean) As AppDomain

Parameters

friendlyName
String

The friendly name of the domain. This friendly name can be displayed in user interfaces to identify the domain. For more information, see FriendlyName.

securityInfo
Evidence

Evidence that establishes the identity of the code that runs in the application domain. Pass null to use the evidence of the current application domain.

appBasePath
String

The base directory that the assembly resolver uses to probe for assemblies. For more information, see BaseDirectory.

appRelativeSearchPath
String

The path relative to the base directory where the assembly resolver should probe for private assemblies. For more information, see RelativeSearchPath.

shadowCopyFiles
Boolean

If true, a shadow copy of an assembly is loaded into this application domain.

Returns

The newly created application domain.

Exceptions

friendlyName is null.

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

If securityInfo is not supplied, the evidence from the current application domain is used.

For more information about shadow copying, see ShadowCopyFiles and Shadow Copying Assemblies.

Important

Do not use this method overload to create sandboxed application domains. Beginning with the .NET Framework 4, the evidence that is supplied for securityInfo no longer affects the grant set of the application domain. Use the CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload to create sandboxed application domains.

Applies to

CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])

Creates a new application domain using the specified name, evidence, application domain setup information, default permission set, and array of fully trusted assemblies.

public:
 static AppDomain ^ CreateDomain(System::String ^ friendlyName, System::Security::Policy::Evidence ^ securityInfo, AppDomainSetup ^ info, System::Security::PermissionSet ^ grantSet, ... cli::array <System::Security::Policy::StrongName ^> ^ fullTrustAssemblies);
public static AppDomain CreateDomain (string friendlyName, System.Security.Policy.Evidence securityInfo, AppDomainSetup info, System.Security.PermissionSet grantSet, params System.Security.Policy.StrongName[] fullTrustAssemblies);
static member CreateDomain : string * System.Security.Policy.Evidence * AppDomainSetup * System.Security.PermissionSet * System.Security.Policy.StrongName[] -> AppDomain
Public Shared Function CreateDomain (friendlyName As String, securityInfo As Evidence, info As AppDomainSetup, grantSet As PermissionSet, ParamArray fullTrustAssemblies As StrongName()) As AppDomain

Parameters

friendlyName
String

The friendly name of the domain. This friendly name can be displayed in user interfaces to identify the domain. For more information, see the description of FriendlyName.

securityInfo
Evidence

Evidence that establishes the identity of the code that runs in the application domain. Pass null to use the evidence of the current application domain.

info
AppDomainSetup

An object that contains application domain initialization information.

grantSet
PermissionSet

A default permission set that is granted to all assemblies loaded into the new application domain that do not have specific grants.

fullTrustAssemblies
StrongName[]

An array of strong names representing assemblies to be considered fully trusted in the new application domain.

Returns

The newly created application domain.

Exceptions

friendlyName is null.

The application domain is null.

-or-

The ApplicationBase property is not set on the AppDomainSetup object that is supplied for info.

Remarks

You must set the ApplicationBase property of the AppDomainSetup object that you supply for info. Otherwise, an exception is thrown.

If securityInfo is not supplied, the evidence from the current application domain is used.

The information provided for grantSet and fullTrustAssemblies is used to create an ApplicationTrust object for the new application domain.

Applies to

CreateDomain(String, Evidence)

Creates a new application domain with the given name using the supplied evidence.

public:
 static AppDomain ^ CreateDomain(System::String ^ friendlyName, System::Security::Policy::Evidence ^ securityInfo);
public static AppDomain CreateDomain (string friendlyName, System.Security.Policy.Evidence securityInfo);
static member CreateDomain : string * System.Security.Policy.Evidence -> AppDomain
Public Shared Function CreateDomain (friendlyName As String, securityInfo As Evidence) As AppDomain

Parameters

friendlyName
String

The friendly name of the domain. This friendly name can be displayed in user interfaces to identify the domain. For more information, see FriendlyName.

securityInfo
Evidence

Evidence that establishes the identity of the code that runs in the application domain. Pass null to use the evidence of the current application domain.

Returns

The newly created application domain.

Exceptions

friendlyName is null.

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

This method overload uses the AppDomainSetup information from the default application domain.

If securityInfo is not supplied, the evidence from the current application domain is used.

Important

Do not use this method overload to create sandboxed application domains. Beginning with the .NET Framework 4, the evidence that is supplied for securityInfo no longer affects the grant set of the application domain. Use the CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload to create sandboxed application domains.

Applies to

CreateDomain(String)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

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);
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}")]
public static AppDomain CreateDomain (string friendlyName);
static member CreateDomain : string -> AppDomain
[<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
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.

See also

Applies to

CreateDomain(String, Evidence, AppDomainSetup)

Creates a new application domain using the specified name, evidence, and application domain setup information.

public:
 static AppDomain ^ CreateDomain(System::String ^ friendlyName, System::Security::Policy::Evidence ^ securityInfo, AppDomainSetup ^ info);
public static AppDomain CreateDomain (string friendlyName, System.Security.Policy.Evidence securityInfo, AppDomainSetup info);
static member CreateDomain : string * System.Security.Policy.Evidence * AppDomainSetup -> AppDomain
Public Shared Function CreateDomain (friendlyName As String, securityInfo As Evidence, info As AppDomainSetup) As AppDomain

Parameters

friendlyName
String

The friendly name of the domain. This friendly name can be displayed in user interfaces to identify the domain. For more information, see FriendlyName.

securityInfo
Evidence

Evidence that establishes the identity of the code that runs in the application domain. Pass null to use the evidence of the current application domain.

info
AppDomainSetup

An object that contains application domain initialization information.

Returns

The newly created application domain.

Exceptions

friendlyName is null.

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

If info is not supplied, this method overload uses the AppDomainSetup information from the default application domain.

If securityInfo is not supplied, the evidence from the current application domain is used.

Important

Do not use this method overload to create sandboxed application domains. Beginning with the .NET Framework 4, the evidence that is supplied for securityInfo no longer affects the grant set of the application domain. Use the CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[]) method overload to create sandboxed application domains.

Applies to