mscorlib(4.0.0.0) API with additions
AppDomainManager.cs
1 using System.Reflection;
5 using System.Security;
8 using System.Threading;
9 
10 namespace System
11 {
14  [SecurityCritical]
15  [ComVisible(true)]
16  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
18  {
20 
21  private ApplicationActivator m_appActivator;
22 
23  private Assembly m_entryAssembly;
24 
28  {
29  get
30  {
31  return m_flags;
32  }
33  set
34  {
35  m_flags = value;
36  }
37  }
38 
42  {
43  get
44  {
45  if (m_appActivator == null)
46  {
47  m_appActivator = new ApplicationActivator();
48  }
49  return m_appActivator;
50  }
51  }
52 
55  public virtual HostSecurityManager HostSecurityManager => null;
56 
59  public virtual HostExecutionContextManager HostExecutionContextManager => HostExecutionContextManager.GetInternalHostExecutionContextManager();
60 
63  public virtual Assembly EntryAssembly
64  {
65  [SecurityCritical]
66  get
67  {
68  if (m_entryAssembly == null)
69  {
70  AppDomain currentDomain = AppDomain.CurrentDomain;
71  if (currentDomain.IsDefaultAppDomain() && currentDomain.ActivationContext != null)
72  {
73  ManifestRunner manifestRunner = new ManifestRunner(currentDomain, currentDomain.ActivationContext);
74  m_entryAssembly = manifestRunner.EntryAssembly;
75  }
76  else
77  {
78  RuntimeAssembly o = null;
79  GetEntryAssembly(JitHelpers.GetObjectHandleOnStack(ref o));
80  m_entryAssembly = o;
81  }
82  }
83  return m_entryAssembly;
84  }
85  }
86 
87  internal static AppDomainManager CurrentAppDomainManager
88  {
89  [SecurityCritical]
90  get
91  {
93  }
94  }
95 
101  [SecurityCritical]
102  public virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
103  {
104  return CreateDomainHelper(friendlyName, securityInfo, appDomainInfo);
105  }
106 
114  [SecurityCritical]
115  [SecurityPermission(SecurityAction.Demand, ControlAppDomain = true)]
116  protected static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
117  {
118  if (friendlyName == null)
119  {
120  throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
121  }
122  if (securityInfo != null)
123  {
124  new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
125  AppDomain.CheckDomainCreationEvidence(appDomainInfo, securityInfo);
126  }
127  if (appDomainInfo == null)
128  {
129  appDomainInfo = new AppDomainSetup();
130  }
131  if (appDomainInfo.AppDomainManagerAssembly == null || appDomainInfo.AppDomainManagerType == null)
132  {
133  AppDomain.CurrentDomain.GetAppDomainManagerType(out string assembly, out string type);
134  if (appDomainInfo.AppDomainManagerAssembly == null)
135  {
136  appDomainInfo.AppDomainManagerAssembly = assembly;
137  }
138  if (appDomainInfo.AppDomainManagerType == null)
139  {
140  appDomainInfo.AppDomainManagerType = type;
141  }
142  }
143  if (appDomainInfo.TargetFrameworkName == null)
144  {
145  appDomainInfo.TargetFrameworkName = AppDomain.CurrentDomain.GetTargetFrameworkName();
146  }
147  return AppDomain.nCreateDomain(friendlyName, appDomainInfo, securityInfo, (securityInfo == null) ? AppDomain.CurrentDomain.InternalEvidence : null, AppDomain.CurrentDomain.GetSecurityDescriptor());
148  }
149 
152  [SecurityCritical]
153  public virtual void InitializeNewDomain(AppDomainSetup appDomainInfo)
154  {
155  }
156 
157  [DllImport("QCall", CharSet = CharSet.Unicode)]
158  [SuppressUnmanagedCodeSecurity]
159  private static extern void GetEntryAssembly(ObjectHandleOnStack retAssembly);
160 
165  public virtual bool CheckSecuritySettings(SecurityState state)
166  {
167  return false;
168  }
169 
170  [MethodImpl(MethodImplOptions.InternalCall)]
171  private static extern bool HasHost();
172 
173  [DllImport("QCall", CharSet = CharSet.Unicode)]
174  [SecurityCritical]
175  [SuppressUnmanagedCodeSecurity]
176  private static extern void RegisterWithHost(IntPtr appDomainManager);
177 
178  internal void RegisterWithHost()
179  {
180  if (HasHost())
181  {
182  IntPtr intPtr = IntPtr.Zero;
184  try
185  {
186  intPtr = Marshal.GetIUnknownForObject(this);
187  RegisterWithHost(intPtr);
188  }
189  finally
190  {
191  if (!intPtr.IsNull())
192  {
193  Marshal.Release(intPtr);
194  }
195  }
196  }
197  }
198  }
199 }
AppDomainManagerInitializationOptions
Specifies the action that a custom application domain manager takes when initializing a new domain.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
virtual ApplicationActivator ApplicationActivator
Gets the application activator that handles the activation of add-ins and manifest-based applications...
string TargetFrameworkName
Gets or sets a string that specifies the target version and profile of the .NET Framework for the app...
virtual bool CheckSecuritySettings(SecurityState state)
Indicates whether the specified operation is allowed in the application domain.
string AppDomainManagerAssembly
Gets or sets the display name of the assembly that provides the type of the application domain manage...
Provides the functionality that allows a common language runtime host to participate in the flow,...
Definition: __Canon.cs:3
static int Release(IntPtr pUnk)
Decrements the reference count on the specified interface.
virtual void InitializeNewDomain(AppDomainSetup appDomainInfo)
Initializes the new application domain.
ActivationContext ActivationContext
Gets the activation context for the current application domain.
Definition: AppDomain.cs:350
virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
Returns a new or existing application domain.
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Definition: AppDomain.cs:274
Represents an application domain, which is an isolated environment where applications execute....
Definition: AppDomain.cs:33
Represents assembly binding information that can be added to an instance of T:System....
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
string AppDomainManagerType
Gets or sets the full name of the type that provides the application domain manager for application d...
bool IsDefaultAppDomain()
Returns a value that indicates whether the application domain is the default application domain for t...
Definition: AppDomain.cs:3949
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
AppDomainManagerInitializationOptions InitializationFlags
Gets the initialization flags for custom application domain managers.
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
Provides a managed equivalent of an unmanaged host.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
virtual Assembly EntryAssembly
Gets the entry assembly for an application.
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
Provides the base class for the activation of manifest-based assemblies.
AppDomainManager DomainManager
Gets the domain manager that was provided by the host when the application domain was initialized.
Definition: AppDomain.cs:245
static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
Provides a helper method to create an application domain.
static IntPtr GetIUnknownForObject(object o)
Returns an IUnknown interface from a managed object.
Definition: Marshal.cs:1882
SecurityPermissionFlag
Specifies access flags for the security permission object.
Allows the control and customization of security behavior for application domains.
Provides a base class for requesting the security status of an action from the T:System....
Definition: SecurityState.cs:8
Provides a set of static methods and properties that provide support for compilers....
Enables access to objects across application domain boundaries in applications that support remoting.