2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System / AppDomain.cs
blobb8c36aa76dfa156f56f043acf03b8c727fb5b413
1 //
2 // System.AppDomain.cs
3 //
4 // Authors:
5 // Paolo Molaro (lupus@ximian.com)
6 // Dietmar Maurer (dietmar@ximian.com)
7 // Miguel de Icaza (miguel@ximian.com)
8 // Gonzalo Paniagua (gonzalo@ximian.com)
9 // Patrik Torstensson
10 // Sebastien Pouliot (sebastien@ximian.com)
12 // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
13 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections;
36 using System.Globalization;
37 using System.IO;
38 using System.Reflection;
39 using System.Reflection.Emit;
40 using System.Threading;
41 using System.Runtime.CompilerServices;
42 using System.Runtime.InteropServices;
43 using System.Runtime.Remoting;
44 using System.Runtime.Remoting.Contexts;
45 using System.Runtime.Remoting.Channels;
46 using System.Runtime.Remoting.Messaging;
47 using System.Security;
48 using System.Security.Permissions;
49 using System.Security.Policy;
50 using System.Security.Principal;
51 using System.Configuration.Assemblies;
53 using System.Collections.Generic;
54 using System.Runtime.ConstrainedExecution;
55 using System.Text;
57 namespace System {
59 [ComVisible (true)]
60 #if !NET_2_1
61 [ComDefaultInterface (typeof (_AppDomain))]
62 #endif
63 [ClassInterface(ClassInterfaceType.None)]
64 #if NET_2_1
65 public sealed class AppDomain : MarshalByRefObject {
66 #else
67 public sealed class AppDomain : MarshalByRefObject, _AppDomain, IEvidenceFactory {
68 #endif
69 #pragma warning disable 169
70 #region Sync with object-internals.h
71 IntPtr _mono_app_domain;
72 #endregion
73 #pragma warning restore 169
74 static string _process_guid;
76 [ThreadStatic]
77 static Hashtable type_resolve_in_progress;
79 [ThreadStatic]
80 static Hashtable assembly_resolve_in_progress;
82 [ThreadStatic]
83 static Hashtable assembly_resolve_in_progress_refonly;
84 #if !MOONLIGHT
85 // CAS
86 private Evidence _evidence;
87 private PermissionSet _granted;
89 // non-CAS
90 private PrincipalPolicy _principalPolicy;
92 [ThreadStatic]
93 private static IPrincipal _principal;
94 #endif
95 static AppDomain default_domain;
97 private AppDomain ()
101 [MethodImplAttribute (MethodImplOptions.InternalCall)]
102 private extern AppDomainSetup getSetup ();
104 #if NET_2_1
105 internal
106 #endif
107 AppDomainSetup SetupInformationNoCopy {
108 get { return getSetup (); }
111 public AppDomainSetup SetupInformation {
112 get {
113 AppDomainSetup setup = getSetup ();
114 return new AppDomainSetup (setup);
118 #if !NET_2_1
119 [MonoTODO]
120 public ApplicationTrust ApplicationTrust {
121 get { throw new NotImplementedException (); }
123 #endif
124 #if !MOONLIGHT
125 public string BaseDirectory {
126 get {
127 string path = SetupInformationNoCopy.ApplicationBase;
128 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
129 // we cannot divulge local file informations
130 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
132 return path;
136 public string RelativeSearchPath {
137 get {
138 string path = SetupInformationNoCopy.PrivateBinPath;
139 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
140 // we cannot divulge local file informations
141 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
143 return path;
147 public string DynamicDirectory {
148 get {
149 AppDomainSetup setup = SetupInformationNoCopy;
150 if (setup.DynamicBase == null)
151 return null;
153 string path = Path.Combine (setup.DynamicBase, setup.ApplicationName);
154 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
155 // we cannot divulge local file informations
156 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
158 return path;
162 public bool ShadowCopyFiles {
163 get {
164 return (SetupInformationNoCopy.ShadowCopyFiles == "true");
167 #endif
169 [MethodImplAttribute (MethodImplOptions.InternalCall)]
170 private extern string getFriendlyName ();
172 public string FriendlyName {
173 get {
174 return getFriendlyName ();
177 #if !MOONLIGHT
178 public Evidence Evidence {
179 get {
180 // if the host (runtime) hasn't provided it's own evidence...
181 if (_evidence == null) {
182 // ... we will provide our own
183 lock (this) {
184 // the executed assembly from the "default" appdomain
185 // or null if we're not in the default appdomain or
186 // if there is no entry assembly (embedded mono)
187 Assembly a = Assembly.GetEntryAssembly ();
188 if (a == null) {
189 if (this == DefaultDomain)
190 // mono is embedded
191 return new Evidence ();
192 else
193 _evidence = AppDomain.DefaultDomain.Evidence;
194 } else {
195 _evidence = Evidence.GetDefaultHostEvidence (a);
199 return new Evidence (_evidence); // return a copy
203 internal IPrincipal DefaultPrincipal {
204 get {
205 if (_principal == null) {
206 switch (_principalPolicy) {
207 case PrincipalPolicy.UnauthenticatedPrincipal:
208 _principal = new GenericPrincipal (
209 new GenericIdentity (String.Empty, String.Empty), null);
210 break;
211 case PrincipalPolicy.WindowsPrincipal:
212 _principal = new WindowsPrincipal (WindowsIdentity.GetCurrent ());
213 break;
216 return _principal;
220 // for AppDomain there is only an allowed (i.e. granted) set
221 // http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondetermininggrantedpermissions.asp
222 internal PermissionSet GrantedPermissionSet {
223 get { return _granted; }
225 #endif
226 [MethodImplAttribute (MethodImplOptions.InternalCall)]
227 private static extern AppDomain getCurDomain ();
229 public static AppDomain CurrentDomain {
230 get {
231 return getCurDomain ();
235 [MethodImplAttribute (MethodImplOptions.InternalCall)]
236 private static extern AppDomain getRootDomain ();
238 internal static AppDomain DefaultDomain {
239 get {
240 if (default_domain == null) {
241 AppDomain rd = getRootDomain ();
242 if (rd == CurrentDomain)
243 default_domain = rd;
244 else
245 default_domain = (AppDomain) RemotingServices.GetDomainProxy (rd);
247 return default_domain;
251 #if !MOONLIGHT
253 [Obsolete ("AppDomain.AppendPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead.")]
254 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
255 public void AppendPrivatePath (string path)
257 if (path == null || path.Length == 0)
258 return;
260 AppDomainSetup setup = SetupInformationNoCopy;
262 string pp = setup.PrivateBinPath;
263 if (pp == null || pp.Length == 0) {
264 setup.PrivateBinPath = path;
265 return;
268 pp = pp.Trim ();
269 if (pp [pp.Length - 1] != Path.PathSeparator)
270 pp += Path.PathSeparator;
272 setup.PrivateBinPath = pp + path;
275 [Obsolete ("AppDomain.ClearPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead.")]
276 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
277 public void ClearPrivatePath ()
279 SetupInformationNoCopy.PrivateBinPath = String.Empty;
282 [Obsolete ("Use AppDomainSetup.ShadowCopyDirectories")]
283 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
284 public void ClearShadowCopyPath ()
286 SetupInformationNoCopy.ShadowCopyDirectories = String.Empty;
289 #if !NET_2_1
290 public ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName)
292 return Activator.CreateComInstanceFrom (assemblyName, typeName);
295 public ObjectHandle CreateComInstanceFrom (string assemblyFile, string typeName,
296 byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
298 return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm);
300 #endif
302 public ObjectHandle CreateInstance (string assemblyName, string typeName)
304 if (assemblyName == null)
305 throw new ArgumentNullException ("assemblyName");
307 return Activator.CreateInstance (assemblyName, typeName);
310 public ObjectHandle CreateInstance (string assemblyName, string typeName, object[] activationAttributes)
312 if (assemblyName == null)
313 throw new ArgumentNullException ("assemblyName");
315 return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
318 #if NET_4_0
319 [Obsolete ("Use an overload that does not take an Evidence parameter")]
320 #endif
321 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
322 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes,
323 Evidence securityAttributes)
325 if (assemblyName == null)
326 throw new ArgumentNullException ("assemblyName");
328 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
329 culture, activationAttributes, securityAttributes);
332 public object CreateInstanceAndUnwrap (string assemblyName, string typeName)
334 ObjectHandle oh = CreateInstance (assemblyName, typeName);
335 return (oh != null) ? oh.Unwrap () : null;
338 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
340 ObjectHandle oh = CreateInstance (assemblyName, typeName, activationAttributes);
341 return (oh != null) ? oh.Unwrap () : null;
344 #if NET_4_0
345 [Obsolete ("Use an overload that does not take an Evidence parameter")]
346 #endif
347 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
348 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
349 object[] activationAttributes, Evidence securityAttributes)
351 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
352 culture, activationAttributes, securityAttributes);
353 return (oh != null) ? oh.Unwrap () : null;
356 #if NET_4_0
357 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
358 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
360 if (assemblyName == null)
361 throw new ArgumentNullException ("assemblyName");
363 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
364 culture, activationAttributes, null);
366 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
367 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
368 object[] activationAttributes)
370 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
371 culture, activationAttributes);
372 return (oh != null) ? oh.Unwrap () : null;
375 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
376 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
377 object[] activationAttributes)
379 if (assemblyFile == null)
380 throw new ArgumentNullException ("assemblyFile");
382 return Activator.CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
383 culture, activationAttributes, null);
386 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
387 BindingFlags bindingAttr, Binder binder, object[] args,
388 CultureInfo culture, object[] activationAttributes)
390 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
391 culture, activationAttributes);
393 return (oh != null) ? oh.Unwrap () : null;
395 #endif
397 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName)
399 if (assemblyFile == null)
400 throw new ArgumentNullException ("assemblyFile");
402 return Activator.CreateInstanceFrom (assemblyFile, typeName);
405 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, object[] activationAttributes)
407 if (assemblyFile == null)
408 throw new ArgumentNullException ("assemblyFile");
410 return Activator.CreateInstanceFrom (assemblyFile, typeName, activationAttributes);
413 #if NET_4_0
414 [Obsolete ("Use an overload that does not take an Evidence parameter")]
415 #endif
416 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
417 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
418 object[] activationAttributes, Evidence securityAttributes)
420 if (assemblyFile == null)
421 throw new ArgumentNullException ("assemblyFile");
423 return Activator.CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
424 culture, activationAttributes, securityAttributes);
427 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName)
429 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName);
430 return (oh != null) ? oh.Unwrap () : null;
433 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
435 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, activationAttributes);
436 return (oh != null) ? oh.Unwrap () : null;
439 #if NET_4_0
440 [Obsolete ("Use an overload that does not take an Evidence parameter")]
441 #endif
442 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
443 BindingFlags bindingAttr, Binder binder, object[] args,
444 CultureInfo culture, object[] activationAttributes,
445 Evidence securityAttributes)
447 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
448 culture, activationAttributes, securityAttributes);
450 return (oh != null) ? oh.Unwrap () : null;
453 #endif // !NET_2_1
455 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
457 return DefineDynamicAssembly (name, access, null, null, null, null, null, false);
460 #if NET_4_0
461 [Obsolete ("Declarative security for assembly level is no longer enforced")]
462 #endif
463 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
465 return DefineDynamicAssembly (name, access, null, evidence, null, null, null, false);
468 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir)
470 return DefineDynamicAssembly (name, access, dir, null, null, null, null, false);
473 #if NET_4_0
474 [Obsolete ("Declarative security for assembly level is no longer enforced")]
475 #endif
476 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
477 Evidence evidence)
479 return DefineDynamicAssembly (name, access, dir, evidence, null, null, null, false);
482 #if NET_4_0
483 [Obsolete ("Declarative security for assembly level is no longer enforced")]
484 #endif
485 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access,
486 PermissionSet requiredPermissions,
487 PermissionSet optionalPermissions,
488 PermissionSet refusedPermissions)
490 return DefineDynamicAssembly (name, access, null, null, requiredPermissions, optionalPermissions,
491 refusedPermissions, false);
494 #if NET_4_0
495 [Obsolete ("Declarative security for assembly level is no longer enforced")]
496 #endif
497 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
498 PermissionSet requiredPermissions,
499 PermissionSet optionalPermissions,
500 PermissionSet refusedPermissions)
502 return DefineDynamicAssembly (name, access, null, evidence, requiredPermissions, optionalPermissions,
503 refusedPermissions, false);
506 #if NET_4_0
507 [Obsolete ("Declarative security for assembly level is no longer enforced")]
508 #endif
509 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
510 PermissionSet requiredPermissions,
511 PermissionSet optionalPermissions,
512 PermissionSet refusedPermissions)
514 return DefineDynamicAssembly (name, access, dir, null, requiredPermissions, optionalPermissions,
515 refusedPermissions, false);
518 #if NET_4_0
519 [Obsolete ("Declarative security for assembly level is no longer enforced")]
520 #endif
521 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
522 Evidence evidence,
523 PermissionSet requiredPermissions,
524 PermissionSet optionalPermissions,
525 PermissionSet refusedPermissions)
527 return DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions,
528 refusedPermissions, false);
531 #if NET_4_0
532 [Obsolete ("Declarative security for assembly level is no longer enforced")]
533 #endif
534 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
535 Evidence evidence,
536 PermissionSet requiredPermissions,
537 PermissionSet optionalPermissions,
538 PermissionSet refusedPermissions, bool isSynchronized)
540 if (name == null)
541 throw new ArgumentNullException ("name");
542 ValidateAssemblyName (name.Name);
544 // FIXME: examine all other parameters
546 AssemblyBuilder ab = new AssemblyBuilder (name, dir, access, false);
547 ab.AddPermissionRequests (requiredPermissions, optionalPermissions, refusedPermissions);
548 return ab;
551 // NET 3.5 method
552 #if NET_4_0
553 [Obsolete ("Declarative security for assembly level is no longer enforced")]
554 #endif
555 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
556 Evidence evidence,
557 PermissionSet requiredPermissions,
558 PermissionSet optionalPermissions,
559 PermissionSet refusedPermissions, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
561 AssemblyBuilder ab = DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, isSynchronized);
562 if (assemblyAttributes != null)
563 foreach (CustomAttributeBuilder cb in assemblyAttributes) {
564 ab.SetCustomAttribute (cb);
566 return ab;
569 // NET 3.5 method
570 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
572 return DefineDynamicAssembly (name, access, null, null, null, null, null, false, assemblyAttributes);
575 #if NET_4_0
576 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
578 return DefineDynamicAssembly (name, access, dir, null, null, null, null, isSynchronized, assemblyAttributes);
581 [MonoLimitation ("The argument securityContextSource is ignored")]
582 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource)
584 return DefineDynamicAssembly (name, access, assemblyAttributes);
586 #endif
588 internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
590 return new AssemblyBuilder (name, null, access, true);
594 // AppDomain.DoCallBack works because AppDomain is a MarshalByRefObject
595 // so, when you call AppDomain.DoCallBack, that's a remote call
597 public void DoCallBack (CrossAppDomainDelegate callBackDelegate)
599 if (callBackDelegate != null)
600 callBackDelegate ();
603 public int ExecuteAssembly (string assemblyFile)
605 return ExecuteAssembly (assemblyFile, (Evidence)null, null);
608 #if NET_4_0
609 [Obsolete ("Use an overload that does not take an Evidence parameter")]
610 #endif
611 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity)
613 return ExecuteAssembly (assemblyFile, assemblySecurity, null);
616 #if NET_4_0
617 [Obsolete ("Use an overload that does not take an Evidence parameter")]
618 #endif
619 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args)
621 Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity);
622 return ExecuteAssemblyInternal (a, args);
625 #if NET_4_0
626 [Obsolete ("Use an overload that does not take an Evidence parameter")]
627 #endif
628 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
630 Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity, hashValue, hashAlgorithm);
631 return ExecuteAssemblyInternal (a, args);
635 #if NET_4_0
636 public int ExecuteAssembly (string assemblyFile, string[] args)
638 Assembly a = Assembly.LoadFrom (assemblyFile, null);
639 return ExecuteAssemblyInternal (a, args);
642 public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
644 Assembly a = Assembly.LoadFrom (assemblyFile, null, hashValue, hashAlgorithm);
645 return ExecuteAssemblyInternal (a, args);
647 #endif
649 int ExecuteAssemblyInternal (Assembly a, string[] args)
651 if (a.EntryPoint == null)
652 throw new MissingMethodException ("Entry point not found in assembly '" + a.FullName + "'.");
653 return ExecuteAssembly (a, args);
656 [MethodImplAttribute (MethodImplOptions.InternalCall)]
657 private extern int ExecuteAssembly (Assembly a, string[] args);
659 [MethodImplAttribute (MethodImplOptions.InternalCall)]
660 private extern Assembly [] GetAssemblies (bool refOnly);
662 public Assembly [] GetAssemblies ()
664 return GetAssemblies (false);
667 [MethodImplAttribute (MethodImplOptions.InternalCall)]
668 public extern object GetData (string name);
670 public new Type GetType()
672 return base.GetType ();
675 public override object InitializeLifetimeService ()
677 return null;
680 [MethodImplAttribute (MethodImplOptions.InternalCall)]
681 internal extern Assembly LoadAssembly (string assemblyRef, Evidence securityEvidence, bool refOnly);
683 public Assembly Load (AssemblyName assemblyRef)
685 return Load (assemblyRef, null);
688 internal Assembly LoadSatellite (AssemblyName assemblyRef, bool throwOnError)
690 if (assemblyRef == null)
691 throw new ArgumentNullException ("assemblyRef");
693 Assembly result = LoadAssembly (assemblyRef.FullName, null, false);
694 if (result == null && throwOnError)
695 throw new FileNotFoundException (null, assemblyRef.Name);
696 return result;
699 #if NET_4_0
700 [Obsolete ("Use an overload that does not take an Evidence parameter")]
701 #endif
702 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
704 if (assemblyRef == null)
705 throw new ArgumentNullException ("assemblyRef");
707 if (assemblyRef.Name == null || assemblyRef.Name.Length == 0) {
708 if (assemblyRef.CodeBase != null)
709 return Assembly.LoadFrom (assemblyRef.CodeBase, assemblySecurity);
710 else
711 throw new ArgumentException (Locale.GetText ("assemblyRef.Name cannot be empty."), "assemblyRef");
714 Assembly assembly = LoadAssembly (assemblyRef.FullName, assemblySecurity, false);
715 if (assembly != null)
716 return assembly;
718 if (assemblyRef.CodeBase == null)
719 throw new FileNotFoundException (null, assemblyRef.Name);
721 string cb = assemblyRef.CodeBase;
722 if (cb.ToLower (CultureInfo.InvariantCulture).StartsWith ("file://"))
723 cb = new Mono.Security.Uri (cb).LocalPath;
725 try {
726 assembly = Assembly.LoadFrom (cb, assemblySecurity);
727 } catch {
728 throw new FileNotFoundException (null, assemblyRef.Name);
730 AssemblyName aname = assembly.GetName ();
731 // Name, version, culture, publickeytoken. Anything else?
732 if (assemblyRef.Name != aname.Name)
733 throw new FileNotFoundException (null, assemblyRef.Name);
735 if (assemblyRef.Version != new Version () && assemblyRef.Version != aname.Version)
736 throw new FileNotFoundException (null, assemblyRef.Name);
738 if (assemblyRef.CultureInfo != null && assemblyRef.CultureInfo.Equals (aname))
739 throw new FileNotFoundException (null, assemblyRef.Name);
741 byte [] pt = assemblyRef.GetPublicKeyToken ();
742 if (pt != null) {
743 byte [] loaded_pt = aname.GetPublicKeyToken ();
744 if (loaded_pt == null || (pt.Length != loaded_pt.Length))
745 throw new FileNotFoundException (null, assemblyRef.Name);
746 for (int i = pt.Length - 1; i >= 0; i--)
747 if (loaded_pt [i] != pt [i])
748 throw new FileNotFoundException (null, assemblyRef.Name);
750 return assembly;
753 public Assembly Load (string assemblyString)
755 return Load (assemblyString, null, false);
758 #if NET_4_0
759 [Obsolete ("Use an overload that does not take an Evidence parameter")]
760 #endif
761 public Assembly Load (string assemblyString, Evidence assemblySecurity)
763 return Load (assemblyString, assemblySecurity, false);
766 internal Assembly Load (string assemblyString, Evidence assemblySecurity, bool refonly)
768 if (assemblyString == null)
769 throw new ArgumentNullException ("assemblyString");
771 if (assemblyString.Length == 0)
772 throw new ArgumentException ("assemblyString cannot have zero length");
774 Assembly assembly = LoadAssembly (assemblyString, assemblySecurity, refonly);
775 if (assembly == null)
776 throw new FileNotFoundException (null, assemblyString);
777 return assembly;
780 public Assembly Load (byte[] rawAssembly)
782 return Load (rawAssembly, null, null);
785 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
787 return Load (rawAssembly, rawSymbolStore, null);
790 [MethodImplAttribute (MethodImplOptions.InternalCall)]
791 internal extern Assembly LoadAssemblyRaw (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence, bool refonly);
793 #if NET_4_0
794 [Obsolete ("Use an overload that does not take an Evidence parameter")]
795 #endif
796 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
798 return Load (rawAssembly, rawSymbolStore, securityEvidence, false);
801 internal Assembly Load (byte [] rawAssembly, byte [] rawSymbolStore, Evidence securityEvidence, bool refonly)
803 if (rawAssembly == null)
804 throw new ArgumentNullException ("rawAssembly");
806 Assembly assembly = LoadAssemblyRaw (rawAssembly, rawSymbolStore, securityEvidence, refonly);
807 assembly.FromByteArray = true;
808 return assembly;
810 #if !MOONLIGHT
811 #if NET_4_0
812 [Obsolete ("AppDomain policy levels are obsolete")]
813 #endif
814 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
815 public void SetAppDomainPolicy (PolicyLevel domainPolicy)
817 if (domainPolicy == null)
818 throw new ArgumentNullException ("domainPolicy");
819 if (_granted != null) {
820 throw new PolicyException (Locale.GetText (
821 "An AppDomain policy is already specified."));
823 if (IsFinalizingForUnload ())
824 throw new AppDomainUnloadedException ();
826 PolicyStatement ps = domainPolicy.Resolve (_evidence);
827 _granted = ps.PermissionSet;
830 [Obsolete ("Use AppDomainSetup.SetCachePath")]
831 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
832 public void SetCachePath (string path)
834 SetupInformationNoCopy.CachePath = path;
837 [SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
838 public void SetPrincipalPolicy (PrincipalPolicy policy)
840 if (IsFinalizingForUnload ())
841 throw new AppDomainUnloadedException ();
843 _principalPolicy = policy;
844 _principal = null;
847 [Obsolete ("Use AppDomainSetup.ShadowCopyFiles")]
848 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
849 public void SetShadowCopyFiles()
851 SetupInformationNoCopy.ShadowCopyFiles = "true";
854 [Obsolete ("Use AppDomainSetup.ShadowCopyDirectories")]
855 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
856 public void SetShadowCopyPath (string path)
858 SetupInformationNoCopy.ShadowCopyDirectories = path;
861 [SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
862 public void SetThreadPrincipal (IPrincipal principal)
864 if (principal == null)
865 throw new ArgumentNullException ("principal");
866 if (_principal != null)
867 throw new PolicyException (Locale.GetText ("principal already present."));
868 if (IsFinalizingForUnload ())
869 throw new AppDomainUnloadedException ();
871 _principal = principal;
873 #endif
874 [MethodImplAttribute (MethodImplOptions.InternalCall)]
875 private static extern AppDomain InternalSetDomainByID (int domain_id);
877 // Changes the active domain and returns the old domain
878 [MethodImplAttribute (MethodImplOptions.InternalCall)]
879 private static extern AppDomain InternalSetDomain (AppDomain context);
881 // Notifies the runtime that this thread references 'domain'.
882 [MethodImplAttribute (MethodImplOptions.InternalCall)]
883 internal static extern void InternalPushDomainRef (AppDomain domain);
885 [MethodImplAttribute (MethodImplOptions.InternalCall)]
886 internal static extern void InternalPushDomainRefByID (int domain_id);
888 // Undoes the effect of the last PushDomainRef call
889 [MethodImplAttribute (MethodImplOptions.InternalCall)]
890 internal static extern void InternalPopDomainRef ();
892 // Changes the active context and returns the old context
893 [MethodImplAttribute (MethodImplOptions.InternalCall)]
894 internal static extern Context InternalSetContext (Context context);
896 // Returns the current context
897 [MethodImplAttribute (MethodImplOptions.InternalCall)]
898 internal static extern Context InternalGetContext ();
900 // Returns the current context
901 [MethodImplAttribute (MethodImplOptions.InternalCall)]
902 internal static extern Context InternalGetDefaultContext ();
904 [MethodImplAttribute (MethodImplOptions.InternalCall)]
905 internal static extern string InternalGetProcessGuid (string newguid);
907 // This method is handled specially by the runtime
908 // It is the only managed method which is allowed to set the current
909 // appdomain
910 internal static object InvokeInDomain (AppDomain domain, MethodInfo method, object obj, object [] args)
912 AppDomain current = CurrentDomain;
913 bool pushed = false;
915 try {
916 Exception exc;
917 InternalPushDomainRef (domain);
918 pushed = true;
919 InternalSetDomain (domain);
920 object o = ((MonoMethod) method).InternalInvoke (obj, args, out exc);
921 if (exc != null)
922 throw exc;
923 return o;
925 finally {
926 InternalSetDomain (current);
927 if (pushed)
928 InternalPopDomainRef ();
932 internal static object InvokeInDomainByID (int domain_id, MethodInfo method, object obj, object [] args)
934 AppDomain current = CurrentDomain;
935 bool pushed = false;
937 try {
938 Exception exc;
939 InternalPushDomainRefByID (domain_id);
940 pushed = true;
941 InternalSetDomainByID (domain_id);
942 object o = ((MonoMethod) method).InternalInvoke (obj, args, out exc);
943 if (exc != null)
944 throw exc;
945 return o;
947 finally {
948 InternalSetDomain (current);
949 if (pushed)
950 InternalPopDomainRef ();
954 internal static String GetProcessGuid ()
956 if (_process_guid == null) {
957 _process_guid = InternalGetProcessGuid (Guid.NewGuid().ToString ());
959 return _process_guid;
962 #if !MOONLIGHT
964 public static AppDomain CreateDomain (string friendlyName)
966 return CreateDomain (friendlyName, null, null);
969 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
971 return CreateDomain (friendlyName, securityInfo, null);
974 [MethodImplAttribute (MethodImplOptions.InternalCall)]
975 private static extern AppDomain createDomain (string friendlyName, AppDomainSetup info);
977 [MonoLimitationAttribute ("Currently it does not allow the setup in the other domain")]
978 [SecurityPermission (SecurityAction.Demand, ControlAppDomain = true)]
979 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info)
981 if (friendlyName == null)
982 throw new System.ArgumentNullException ("friendlyName");
984 AppDomain def = AppDomain.DefaultDomain;
985 if (info == null) {
986 // if null, get default domain's SetupInformation
987 if (def == null)
988 info = new AppDomainSetup (); // we're default!
989 else
990 info = def.SetupInformation;
992 else
993 info = new AppDomainSetup (info); // copy
995 // todo: allow setup in the other domain
996 if (def != null) {
997 if (!info.Equals (def.SetupInformation)) {
998 // If not specified use default domain's app base.
999 if (info.ApplicationBase == null)
1000 info.ApplicationBase = def.SetupInformation.ApplicationBase;
1001 if (info.ConfigurationFile == null)
1002 info.ConfigurationFile = Path.GetFileName (def.SetupInformation.ConfigurationFile);
1004 } else if (info.ConfigurationFile == null)
1005 info.ConfigurationFile = "[I don't have a config file]";
1007 #if !NET_2_1
1008 if (info.AppDomainInitializer != null) {
1009 if (!info.AppDomainInitializer.Method.IsStatic)
1010 throw new ArgumentException ("Non-static methods cannot be invoked as an appdomain initializer");
1012 #endif
1014 info.SerializeNonPrimitives ();
1016 AppDomain ad = (AppDomain) RemotingServices.GetDomainProxy (createDomain (friendlyName, info));
1017 if (securityInfo == null) {
1018 // get default domain's Evidence (unless we're are the default!)
1019 if (def == null)
1020 ad._evidence = null; // we'll get them later (GetEntryAssembly)
1021 else
1022 ad._evidence = def.Evidence; // new (shallow) copy
1024 else
1025 ad._evidence = new Evidence (securityInfo); // copy
1027 #if !NET_2_1
1028 if (info.AppDomainInitializer != null) {
1029 Loader loader = new Loader (
1030 info.AppDomainInitializer.Method.DeclaringType.Assembly.Location);
1031 ad.DoCallBack (loader.Load);
1033 Initializer initializer = new Initializer (
1034 info.AppDomainInitializer,
1035 info.AppDomainInitializerArguments);
1036 ad.DoCallBack (initializer.Initialize);
1038 #endif
1040 return ad;
1043 #if !NET_2_1
1044 [Serializable]
1045 class Loader {
1047 string assembly;
1049 public Loader (string assembly)
1051 this.assembly = assembly;
1054 public void Load ()
1056 Assembly.LoadFrom (assembly);
1060 [Serializable]
1061 class Initializer {
1063 AppDomainInitializer initializer;
1064 string [] arguments;
1066 public Initializer (AppDomainInitializer initializer, string [] arguments)
1068 this.initializer = initializer;
1069 this.arguments = arguments;
1072 public void Initialize ()
1074 initializer (arguments);
1077 #endif
1079 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,string appBasePath,
1080 string appRelativeSearchPath, bool shadowCopyFiles)
1082 return CreateDomain (friendlyName, securityInfo, CreateDomainSetup (appBasePath, appRelativeSearchPath, shadowCopyFiles));
1085 #if !NET_2_1
1086 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info,
1087 PermissionSet grantSet, params StrongName [] fullTrustAssemblies)
1089 if (info == null)
1090 throw new ArgumentNullException ("info");
1092 info.ApplicationTrust = new ApplicationTrust (grantSet, fullTrustAssemblies ?? new StrongName [0]);
1093 return CreateDomain (friendlyName, securityInfo, info);
1095 #endif
1097 static AppDomainSetup CreateDomainSetup (string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles)
1099 AppDomainSetup info = new AppDomainSetup ();
1101 info.ApplicationBase = appBasePath;
1102 info.PrivateBinPath = appRelativeSearchPath;
1104 if (shadowCopyFiles)
1105 info.ShadowCopyFiles = "true";
1106 else
1107 info.ShadowCopyFiles = "false";
1109 return info;
1111 #endif // !NET_2_1
1113 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1114 private static extern bool InternalIsFinalizingForUnload (int domain_id);
1116 public bool IsFinalizingForUnload()
1118 return InternalIsFinalizingForUnload (getDomainID ());
1121 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1122 static extern void InternalUnload (int domain_id);
1124 // We do this because if the domain is a transparant proxy this
1125 // will still return the correct domain id.
1126 private int getDomainID ()
1128 return Thread.GetDomainID ();
1131 [SecurityPermission (SecurityAction.Demand, ControlAppDomain = true)]
1132 [ReliabilityContractAttribute (Consistency.MayCorruptAppDomain, Cer.MayFail)]
1133 public static void Unload (AppDomain domain)
1135 if (domain == null)
1136 throw new ArgumentNullException ("domain");
1138 InternalUnload (domain.getDomainID());
1141 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1142 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1143 public extern void SetData (string name, object data);
1145 [MonoLimitation ("The permission field is ignored")]
1146 public void SetData (string name, object data, IPermission permission)
1148 SetData (name, data);
1151 #if !NET_2_1
1152 [Obsolete ("Use AppDomainSetup.DynamicBase")]
1153 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1154 public void SetDynamicBase (string path)
1156 SetupInformationNoCopy.DynamicBase = path;
1158 #endif // !NET_2_1
1160 [Obsolete ("AppDomain.GetCurrentThreadId has been deprecated"
1161 + " because it does not provide a stable Id when managed"
1162 + " threads are running on fibers (aka lightweight"
1163 + " threads). To get a stable identifier for a managed"
1164 + " thread, use the ManagedThreadId property on Thread.'")]
1165 public static int GetCurrentThreadId ()
1167 return Thread.CurrentThreadId;
1170 public override string ToString ()
1172 #if !MOONLIGHT
1173 return getFriendlyName ();
1174 #else
1175 StringBuilder sb = new StringBuilder ("Name:");
1176 sb.AppendLine (FriendlyName);
1177 sb.AppendLine ("There are no context policies.");
1178 return sb.ToString ();
1179 #endif
1182 private static void ValidateAssemblyName (string name)
1184 if (name == null || name.Length == 0)
1185 throw new ArgumentException ("The Name of " +
1186 "AssemblyName cannot be null or a " +
1187 "zero-length string.");
1189 bool isValid = true;
1191 for (int i = 0; i < name.Length; i++) {
1192 char c = name [i];
1194 // do not allow leading whitespace
1195 if (i == 0 && char.IsWhiteSpace (c)) {
1196 isValid = false;
1197 break;
1200 // do not allow /,\ or : in name
1201 if (c == '/' || c == '\\' || c == ':') {
1202 isValid = false;
1203 break;
1207 if (!isValid)
1208 throw new ArgumentException ("The Name of " +
1209 "AssemblyName cannot start with " +
1210 "whitespace, or contain '/', '\\' " +
1211 " or ':'.");
1214 // The following methods are called from the runtime. Don't change signatures.
1215 #pragma warning disable 169
1216 private void DoAssemblyLoad (Assembly assembly)
1218 if (AssemblyLoad == null)
1219 return;
1221 AssemblyLoad (this, new AssemblyLoadEventArgs (assembly));
1224 private Assembly DoAssemblyResolve (string name, bool refonly)
1226 ResolveEventHandler del;
1227 #if !NET_2_1
1228 if (refonly)
1229 del = ReflectionOnlyAssemblyResolve;
1230 else
1231 del = AssemblyResolve;
1232 #else
1233 del = AssemblyResolve;
1234 #endif
1235 if (del == null)
1236 return null;
1238 /* Prevent infinite recursion */
1239 Hashtable ht;
1240 if (refonly) {
1241 ht = assembly_resolve_in_progress_refonly;
1242 if (ht == null) {
1243 ht = new Hashtable ();
1244 assembly_resolve_in_progress_refonly = ht;
1246 } else {
1247 ht = assembly_resolve_in_progress;
1248 if (ht == null) {
1249 ht = new Hashtable ();
1250 assembly_resolve_in_progress = ht;
1254 string s = (string) ht [name];
1255 if (s != null)
1256 return null;
1257 ht [name] = name;
1258 try {
1259 Delegate[] invocation_list = del.GetInvocationList ();
1261 foreach (Delegate eh in invocation_list) {
1262 ResolveEventHandler handler = (ResolveEventHandler) eh;
1263 Assembly assembly = handler (this, new ResolveEventArgs (name));
1264 if (assembly != null)
1265 return assembly;
1267 return null;
1269 finally {
1270 ht.Remove (name);
1274 internal Assembly DoTypeResolve (Object name_or_tb)
1276 if (TypeResolve == null)
1277 return null;
1279 string name;
1281 if (name_or_tb is TypeBuilder)
1282 name = ((TypeBuilder) name_or_tb).FullName;
1283 else
1284 name = (string) name_or_tb;
1286 /* Prevent infinite recursion */
1287 Hashtable ht = type_resolve_in_progress;
1288 if (ht == null) {
1289 ht = new Hashtable ();
1290 type_resolve_in_progress = ht;
1293 if (ht.Contains (name))
1294 return null;
1295 else
1296 ht [name] = name;
1298 try {
1299 foreach (Delegate d in TypeResolve.GetInvocationList ()) {
1300 ResolveEventHandler eh = (ResolveEventHandler) d;
1301 Assembly assembly = eh (this, new ResolveEventArgs (name));
1302 if (assembly != null)
1303 return assembly;
1305 return null;
1307 finally {
1308 ht.Remove (name);
1312 private void DoDomainUnload ()
1314 if (DomainUnload != null)
1315 DomainUnload(this, null);
1318 #if !NET_2_1
1319 internal byte[] GetMarshalledDomainObjRef ()
1321 ObjRef oref = RemotingServices.Marshal (AppDomain.CurrentDomain, null, typeof (AppDomain));
1322 return CADSerializer.SerializeObject (oref).GetBuffer();
1324 #endif
1325 internal void ProcessMessageInDomain (byte[] arrRequest, CADMethodCallMessage cadMsg,
1326 out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
1328 IMessage reqDomMsg;
1330 if (null != arrRequest)
1331 reqDomMsg = CADSerializer.DeserializeMessage (new MemoryStream(arrRequest), null);
1332 else
1333 reqDomMsg = new MethodCall (cadMsg);
1335 IMessage retDomMsg = ChannelServices.SyncDispatchMessage (reqDomMsg);
1337 cadMrm = CADMethodReturnMessage.Create (retDomMsg);
1338 if (null == cadMrm) {
1339 arrResponse = CADSerializer.SerializeMessage (retDomMsg).GetBuffer();
1341 else
1342 arrResponse = null;
1345 #pragma warning restore 169
1347 // End of methods called from the runtime
1349 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1350 public event AssemblyLoadEventHandler AssemblyLoad;
1352 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1353 public event ResolveEventHandler AssemblyResolve;
1355 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1356 public event EventHandler DomainUnload;
1358 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1359 public event EventHandler ProcessExit;
1361 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1362 public event ResolveEventHandler ResourceResolve;
1364 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1365 public event ResolveEventHandler TypeResolve;
1367 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1368 public event UnhandledExceptionEventHandler UnhandledException;
1370 #if NET_4_0 || BOOTSTRAP_NET_4_0
1371 [MonoTODO]
1372 public bool IsHomogenous {
1373 get { return true; }
1375 #endif
1377 #pragma warning disable 649
1378 private AppDomainManager _domain_manager;
1379 #pragma warning restore 649
1381 // default is null
1382 public AppDomainManager DomainManager {
1383 get { return _domain_manager; }
1386 #if (!MOONLIGHT)
1388 public event ResolveEventHandler ReflectionOnlyAssemblyResolve;
1390 #pragma warning disable 649
1391 private ActivationContext _activation;
1392 private ApplicationIdentity _applicationIdentity;
1393 #pragma warning restore 649
1395 // properties
1397 public ActivationContext ActivationContext {
1398 get { return _activation; }
1401 public ApplicationIdentity ApplicationIdentity {
1402 get { return _applicationIdentity; }
1405 public int Id {
1406 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
1407 get { return getDomainID (); }
1410 // methods
1412 [MonoTODO ("This routine only returns the parameter currently")]
1413 [ComVisible (false)]
1414 public string ApplyPolicy (string assemblyName)
1416 if (assemblyName == null)
1417 throw new ArgumentNullException ("assemblyName");
1418 if (assemblyName.Length == 0) // String.Empty
1419 throw new ArgumentException ("assemblyName");
1420 return assemblyName;
1423 // static methods
1425 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, string appBasePath,
1426 string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
1428 AppDomainSetup info = CreateDomainSetup (appBasePath, appRelativeSearchPath, shadowCopyFiles);
1430 info.AppDomainInitializerArguments = adInitArgs;
1431 info.AppDomainInitializer = adInit;
1433 return CreateDomain (friendlyName, securityInfo, info);
1436 public int ExecuteAssemblyByName (string assemblyName)
1438 return ExecuteAssemblyByName (assemblyName, (Evidence)null, null);
1441 #if NET_4_0
1442 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1443 #endif
1444 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity)
1446 return ExecuteAssemblyByName (assemblyName, assemblySecurity, null);
1449 #if NET_4_0
1450 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1451 #endif
1452 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity, params string[] args)
1454 Assembly a = Assembly.Load (assemblyName, assemblySecurity);
1456 return ExecuteAssemblyInternal (a, args);
1459 #if NET_4_0
1460 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1461 #endif
1462 public int ExecuteAssemblyByName (AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
1464 Assembly a = Assembly.Load (assemblyName, assemblySecurity);
1466 return ExecuteAssemblyInternal (a, args);
1469 #if NET_4_0
1470 public int ExecuteAssemblyByName (string assemblyName, params string[] args)
1472 Assembly a = Assembly.Load (assemblyName, null);
1474 return ExecuteAssemblyInternal (a, args);
1477 public int ExecuteAssemblyByName (AssemblyName assemblyName, params string[] args)
1479 Assembly a = Assembly.Load (assemblyName, null);
1481 return ExecuteAssemblyInternal (a, args);
1483 #endif
1485 public bool IsDefaultAppDomain ()
1487 return Object.ReferenceEquals (this, DefaultDomain);
1490 public Assembly[] ReflectionOnlyGetAssemblies ()
1492 return GetAssemblies (true);
1495 #else // MOONLIGHT
1497 public int ExecuteAssemblyByName (string assemblyName)
1499 // critical code in SL that we're not calling in ML
1500 throw new NotImplementedException ();
1502 #endif
1504 #if !NET_2_1
1505 void _AppDomain.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1507 throw new NotImplementedException ();
1510 void _AppDomain.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1512 throw new NotImplementedException ();
1515 void _AppDomain.GetTypeInfoCount (out uint pcTInfo)
1517 throw new NotImplementedException ();
1520 void _AppDomain.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams,
1521 IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1523 throw new NotImplementedException ();
1525 #endif
1527 #if NET_4_0 || MOONLIGHT
1528 [MonoTODO ("Currently always returns false")]
1529 public bool? IsCompatibilitySwitchSet (string value)
1531 if (value == null)
1532 throw new ArgumentNullException ("value");
1533 // default (at least for SL4) is to return false for unknown values (can't get a null out of it)
1534 return false;
1537 [MonoTODO ("Currently always returns false")]
1538 public static bool MonitoringIsEnabled {
1539 get { return false; }
1540 set { throw new NotImplementedException (); }
1543 [MonoTODO]
1544 public long MonitoringSurvivedMemorySize {
1545 get { throw new NotImplementedException (); }
1548 [MonoTODO]
1549 public static long MonitoringSurvivedProcessMemorySize {
1550 get { throw new NotImplementedException (); }
1553 [MonoTODO]
1554 public long MonitoringTotalAllocatedMemorySize {
1555 get { throw new NotImplementedException (); }
1558 [MonoTODO]
1559 public TimeSpan MonitoringTotalProcessorTime {
1560 get { throw new NotImplementedException (); }
1562 #endif