.NET Framework Class Library
AppDomain..::.CreateDomain Method (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.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function CreateDomain ( _
    friendlyName As String, _
    securityInfo As Evidence, _
    appBasePath As String, _
    appRelativeSearchPath As String, _
    shadowCopyFiles As Boolean _
) As AppDomain
Visual Basic (Usage)
Dim friendlyName As String
Dim securityInfo As Evidence
Dim appBasePath As String
Dim appRelativeSearchPath As String
Dim shadowCopyFiles As Boolean
Dim returnValue As AppDomain

returnValue = AppDomain.CreateDomain(friendlyName, _
    securityInfo, appBasePath, appRelativeSearchPath, _
    shadowCopyFiles)
C#
public static AppDomain CreateDomain(
    string friendlyName,
    Evidence securityInfo,
    string appBasePath,
    string appRelativeSearchPath,
    bool shadowCopyFiles
)
Visual C++
public:
static AppDomain^ CreateDomain(
    String^ friendlyName, 
    Evidence^ securityInfo, 
    String^ appBasePath, 
    String^ appRelativeSearchPath, 
    bool shadowCopyFiles
)
JScript
public static function CreateDomain(
    friendlyName : String, 
    securityInfo : Evidence, 
    appBasePath : String, 
    appRelativeSearchPath : String, 
    shadowCopyFiles : boolean
) : AppDomain

Parameters

friendlyName
Type: System..::.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
Type: System.Security.Policy..::.Evidence
Evidence mapped through the security policy to establish a top-of-stack permission set. Pass nullNothingnullptra null reference (Nothing in Visual Basic) to use the evidence of the current application domain.
appBasePath
Type: System..::.String
The base directory that the assembly resolver uses to probe for assemblies. For more information, see BaseDirectory.
appRelativeSearchPath
Type: System..::.String
The path relative to the base directory where the assembly resolver should probe for private assemblies. For more information, see RelativeSearchPath.
shadowCopyFiles
Type: System..::.Boolean
If true, a shadow copy of an assembly is loaded into this application domain. For more information, see ShadowCopyFiles and Shadow Copying Assemblies.

Return Value

Type: System..::.AppDomain
The newly created application domain.
Exceptions

ExceptionCondition
ArgumentNullException

friendlyName is nullNothingnullptra null reference (Nothing in Visual Basic).

Remarks

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

If the current application domain has an empty Evidence, SecurityException is thrown when creating a new application domain and passing nullNothingnullptra null reference (Nothing in Visual Basic) for securityInfo. An empty Evidence always results in an empty grant set. For example, a default application domain can have an empty Evidence if it is created from unmanaged code.

Examples

The following sample demonstrates, in general, how to create a domain using one of the CreateDomain overloads.

Visual Basic
' 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)
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);
Visual C++
// 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 );
.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Page view tracker