AppDomainSetup provides configuration information for a new application domain which is an isolated environment in which Microsoft .NET assemblies can be sandboxed, granted specific permissions or PermissionSets and executed.
Definition:
An AppDomainSetup represents configuration information for a new application domain in which compiled Microsoft .NET assemblies can be isolated from other assemblies. While AppDomains are typically used to sandbox third-party or otherwise untrusted code, they can also be used to separate code from the main process to prevent potential instability in a specific segment of an application.
When creating your application domains, the most important property is ApplicationBase
which defines the root directory of the application and also used for probing for the types and assemblies in the directory specified by the ApplicationBase property.
Tag Usage:
The appdomainsetup tag should be used when referencing issues related to the System.AppDomainSetup
class in Microsoft .NET or related remoting or process issues.
Example (C#):
namespace AppDomainSetupExample
{
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
class Program
{
static void Main(string[] args)
{
PermissionSet ps = new PermissionSet(PermissionState.None);
ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
ps.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, @"C:\"));
var assembly = Assembly.GetExecutingAssembly();
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = Path.GetFullPath(assembly.Location);
StrongName fullTrustAssemblies = assembly.Evidence.GetHostEvidence<StrongName>();
AppDomain domain = AppDomain.CreateDomain("foo", null, ads, ps, fullTrustAssemblies);
}
}
}