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.

C#
public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs);

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.

Dôležité

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

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 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

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.

C#
public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo, string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles);

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.

C#
// 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);

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.

Dôležité

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

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.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

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.

C#
public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo, AppDomainSetup info, System.Security.PermissionSet grantSet, params System.Security.Policy.StrongName[] fullTrustAssemblies);

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

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 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

CreateDomain(String, Evidence)

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

C#
public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo);

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.

C#
// 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);

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.

Dôležité

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

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.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

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.

C#
[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);
C#
public static AppDomain CreateDomain(string friendlyName);

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.

C#
// 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);

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

.NET 10 a ďalšie verzie
Produkt Verzie (Zastarané)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5 (6, 7, 8, 9, 10)
.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
.NET Standard 2.0, 2.1

CreateDomain(String, Evidence, AppDomainSetup)

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

C#
public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo, AppDomainSetup info);

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.

C#
// 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);

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.

Dôležité

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

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.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