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)
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)
14 // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Globalization;
38 using System.Reflection;
40 using System.Reflection.Emit;
42 using System.Threading;
43 using System.Runtime.CompilerServices;
44 using System.Runtime.ExceptionServices;
45 using System.Runtime.InteropServices;
46 using System.Runtime.Remoting;
47 using System.Runtime.Remoting.Contexts;
48 using System.Runtime.Remoting.Channels;
49 using System.Runtime.Remoting.Messaging;
50 using System.Security;
51 using System.Security.Permissions;
52 using System.Security.Policy;
53 using System.Security.Principal;
54 using System.Configuration.Assemblies;
56 using System.Collections.Generic;
57 using System.Runtime.ConstrainedExecution;
64 [ComDefaultInterface (typeof (_AppDomain))]
66 [ClassInterface(ClassInterfaceType.None)]
67 [StructLayout (LayoutKind.Sequential)]
69 public sealed partial class AppDomain : MarshalByRefObject {
71 public sealed partial class AppDomain : MarshalByRefObject, _AppDomain, IEvidenceFactory {
73 #pragma warning disable 169
74 #region Sync with object-internals.h
75 IntPtr _mono_app_domain;
77 #pragma warning restore 169
78 static string _process_guid;
81 static Dictionary<string, object> type_resolve_in_progress;
84 static Dictionary<string, object> assembly_resolve_in_progress;
87 static Dictionary<string, object> assembly_resolve_in_progress_refonly;
90 private Evidence _evidence;
91 private PermissionSet _granted;
94 private PrincipalPolicy _principalPolicy;
97 private static IPrincipal _principal;
103 int _principalPolicy;
106 static object _principal;
110 static AppDomain default_domain;
116 [MethodImplAttribute (MethodImplOptions.InternalCall)]
117 private extern AppDomainSetup getSetup ();
122 AppDomainSetup SetupInformationNoCopy {
123 get { return getSetup (); }
126 public AppDomainSetup SetupInformation {
128 AppDomainSetup setup = getSetup ();
129 return new AppDomainSetup (setup);
135 public ApplicationTrust ApplicationTrust {
136 get { throw new NotImplementedException (); }
139 public string BaseDirectory {
141 string path = SetupInformationNoCopy.ApplicationBase;
143 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
144 // we cannot divulge local file informations
145 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
152 public string RelativeSearchPath {
154 string path = SetupInformationNoCopy.PrivateBinPath;
156 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
157 // we cannot divulge local file informations
158 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
165 public string DynamicDirectory {
167 AppDomainSetup setup = SetupInformationNoCopy;
168 if (setup.DynamicBase == null)
171 string path = Path.Combine (setup.DynamicBase, setup.ApplicationName);
173 if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
174 // we cannot divulge local file informations
175 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
182 public bool ShadowCopyFiles {
184 return (SetupInformationNoCopy.ShadowCopyFiles == "true");
188 [MethodImplAttribute (MethodImplOptions.InternalCall)]
189 private extern string getFriendlyName ();
191 public string FriendlyName {
193 return getFriendlyName ();
197 public Evidence Evidence {
202 // if the host (runtime) hasn't provided it's own evidence...
203 if (_evidence == null) {
204 // ... we will provide our own
206 // the executed assembly from the "default" appdomain
207 // or null if we're not in the default appdomain or
208 // if there is no entry assembly (embedded mono)
209 Assembly a = Assembly.GetEntryAssembly ();
211 if (this == DefaultDomain)
213 return new Evidence ();
215 _evidence = AppDomain.DefaultDomain.Evidence;
217 _evidence = Evidence.GetDefaultHostEvidence (a);
221 return new Evidence ((Evidence)_evidence); // return a copy
226 internal IPrincipal DefaultPrincipal {
228 if (_principal == null) {
229 switch ((PrincipalPolicy)_principalPolicy) {
230 case PrincipalPolicy.UnauthenticatedPrincipal:
231 _principal = new GenericPrincipal (
232 new GenericIdentity (String.Empty, String.Empty), null);
234 case PrincipalPolicy.WindowsPrincipal:
235 _principal = new WindowsPrincipal (WindowsIdentity.GetCurrent ());
239 return (IPrincipal)_principal;
243 // for AppDomain there is only an allowed (i.e. granted) set
244 // http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondetermininggrantedpermissions.asp
245 internal PermissionSet GrantedPermissionSet {
246 get { return (PermissionSet)_granted; }
249 public PermissionSet PermissionSet {
250 get { return (PermissionSet)_granted ?? (PermissionSet)(_granted = new PermissionSet (PermissionState.Unrestricted)); }
253 [MethodImplAttribute (MethodImplOptions.InternalCall)]
254 private static extern AppDomain getCurDomain ();
256 public static AppDomain CurrentDomain {
258 return getCurDomain ();
262 [MethodImplAttribute (MethodImplOptions.InternalCall)]
263 private static extern AppDomain getRootDomain ();
265 internal static AppDomain DefaultDomain {
267 if (default_domain == null) {
268 AppDomain rd = getRootDomain ();
269 if (rd == CurrentDomain)
272 default_domain = (AppDomain) RemotingServices.GetDomainProxy (rd);
274 return default_domain;
278 [Obsolete ("AppDomain.AppendPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead.")]
279 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
280 public void AppendPrivatePath (string path)
282 if (path == null || path.Length == 0)
285 AppDomainSetup setup = SetupInformationNoCopy;
287 string pp = setup.PrivateBinPath;
288 if (pp == null || pp.Length == 0) {
289 setup.PrivateBinPath = path;
294 if (pp [pp.Length - 1] != Path.PathSeparator)
295 pp += Path.PathSeparator;
297 setup.PrivateBinPath = pp + path;
300 [Obsolete ("AppDomain.ClearPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead.")]
301 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
302 public void ClearPrivatePath ()
304 SetupInformationNoCopy.PrivateBinPath = String.Empty;
307 [Obsolete ("Use AppDomainSetup.ShadowCopyDirectories")]
308 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
309 public void ClearShadowCopyPath ()
311 SetupInformationNoCopy.ShadowCopyDirectories = String.Empty;
315 public ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName)
317 return Activator.CreateComInstanceFrom (assemblyName, typeName);
320 public ObjectHandle CreateComInstanceFrom (string assemblyFile, string typeName,
321 byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
323 return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm);
327 internal ObjectHandle InternalCreateInstanceWithNoSecurity (string assemblyName, string typeName)
329 return CreateInstance(assemblyName, typeName);
332 internal ObjectHandle InternalCreateInstanceWithNoSecurity (string assemblyName,
335 BindingFlags bindingAttr,
339 Object[] activationAttributes,
340 Evidence securityAttributes)
342 #pragma warning disable 618
343 return CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
344 #pragma warning restore 618
347 internal ObjectHandle InternalCreateInstanceFromWithNoSecurity (string assemblyName, string typeName)
349 return CreateInstanceFrom(assemblyName, typeName);
352 internal ObjectHandle InternalCreateInstanceFromWithNoSecurity (string assemblyName,
355 BindingFlags bindingAttr,
359 Object[] activationAttributes,
360 Evidence securityAttributes)
362 #pragma warning disable 618
363 return CreateInstanceFrom(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes);
364 #pragma warning restore 618
367 public ObjectHandle CreateInstance (string assemblyName, string typeName)
369 if (assemblyName == null)
370 throw new ArgumentNullException ("assemblyName");
372 return Activator.CreateInstance (assemblyName, typeName);
375 public ObjectHandle CreateInstance (string assemblyName, string typeName, object[] activationAttributes)
377 if (assemblyName == null)
378 throw new ArgumentNullException ("assemblyName");
380 return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
383 [Obsolete ("Use an overload that does not take an Evidence parameter")]
384 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
385 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes,
386 Evidence securityAttributes)
388 if (assemblyName == null)
389 throw new ArgumentNullException ("assemblyName");
391 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
392 culture, activationAttributes, securityAttributes);
395 public object CreateInstanceAndUnwrap (string assemblyName, string typeName)
397 ObjectHandle oh = CreateInstance (assemblyName, typeName);
398 return (oh != null) ? oh.Unwrap () : null;
401 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
403 ObjectHandle oh = CreateInstance (assemblyName, typeName, activationAttributes);
404 return (oh != null) ? oh.Unwrap () : null;
407 [Obsolete ("Use an overload that does not take an Evidence parameter")]
408 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
409 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
410 object[] activationAttributes, Evidence securityAttributes)
412 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
413 culture, activationAttributes, securityAttributes);
414 return (oh != null) ? oh.Unwrap () : null;
417 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
418 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
420 if (assemblyName == null)
421 throw new ArgumentNullException ("assemblyName");
423 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
424 culture, activationAttributes, null);
426 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
427 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
428 object[] activationAttributes)
430 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
431 culture, activationAttributes);
432 return (oh != null) ? oh.Unwrap () : null;
435 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
436 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
437 object[] activationAttributes)
439 if (assemblyFile == null)
440 throw new ArgumentNullException ("assemblyFile");
442 return Activator.CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
443 culture, activationAttributes, null);
446 public object CreateInstanceFromAndUnwrap (string assemblyFile, string typeName, bool ignoreCase,
447 BindingFlags bindingAttr, Binder binder, object[] args,
448 CultureInfo culture, object[] activationAttributes)
450 ObjectHandle oh = CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
451 culture, activationAttributes);
453 return (oh != null) ? oh.Unwrap () : null;
456 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName)
458 if (assemblyFile == null)
459 throw new ArgumentNullException ("assemblyFile");
461 return Activator.CreateInstanceFrom (assemblyFile, typeName);
464 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, object[] activationAttributes)
466 if (assemblyFile == null)
467 throw new ArgumentNullException ("assemblyFile");
469 return Activator.CreateInstanceFrom (assemblyFile, typeName, activationAttributes);
472 [Obsolete ("Use an overload that does not take an Evidence parameter")]
473 public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
474 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
475 object[] activationAttributes, Evidence securityAttributes)
477 if (assemblyFile == null)
478 throw new ArgumentNullException ("assemblyFile");
480 return Activator.CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
481 culture, activationAttributes, securityAttributes);
484 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName)
486 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName);
487 return (oh != null) ? oh.Unwrap () : null;
490 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
492 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, activationAttributes);
493 return (oh != null) ? oh.Unwrap () : null;
496 [Obsolete ("Use an overload that does not take an Evidence parameter")]
497 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
498 BindingFlags bindingAttr, Binder binder, object[] args,
499 CultureInfo culture, object[] activationAttributes,
500 Evidence securityAttributes)
502 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
503 culture, activationAttributes, securityAttributes);
505 return (oh != null) ? oh.Unwrap () : null;
508 #if !FULL_AOT_RUNTIME
509 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
511 return DefineDynamicAssembly (name, access, null, null, null, null, null, false);
514 [Obsolete ("Declarative security for assembly level is no longer enforced")]
515 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
517 return DefineDynamicAssembly (name, access, null, evidence, null, null, null, false);
520 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir)
522 return DefineDynamicAssembly (name, access, dir, null, null, null, null, false);
525 [Obsolete ("Declarative security for assembly level is no longer enforced")]
526 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
529 return DefineDynamicAssembly (name, access, dir, evidence, null, null, null, false);
532 [Obsolete ("Declarative security for assembly level is no longer enforced")]
533 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access,
534 PermissionSet requiredPermissions,
535 PermissionSet optionalPermissions,
536 PermissionSet refusedPermissions)
538 return DefineDynamicAssembly (name, access, null, null, requiredPermissions, optionalPermissions,
539 refusedPermissions, false);
542 [Obsolete ("Declarative security for assembly level is no longer enforced")]
543 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
544 PermissionSet requiredPermissions,
545 PermissionSet optionalPermissions,
546 PermissionSet refusedPermissions)
548 return DefineDynamicAssembly (name, access, null, evidence, requiredPermissions, optionalPermissions,
549 refusedPermissions, false);
552 [Obsolete ("Declarative security for assembly level is no longer enforced")]
553 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
554 PermissionSet requiredPermissions,
555 PermissionSet optionalPermissions,
556 PermissionSet refusedPermissions)
558 return DefineDynamicAssembly (name, access, dir, null, requiredPermissions, optionalPermissions,
559 refusedPermissions, false);
562 [Obsolete ("Declarative security for assembly level is no longer enforced")]
563 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
565 PermissionSet requiredPermissions,
566 PermissionSet optionalPermissions,
567 PermissionSet refusedPermissions)
569 return DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions,
570 refusedPermissions, false);
573 [Obsolete ("Declarative security for assembly level is no longer enforced")]
574 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
576 PermissionSet requiredPermissions,
577 PermissionSet optionalPermissions,
578 PermissionSet refusedPermissions, bool isSynchronized)
581 throw new ArgumentNullException ("name");
582 ValidateAssemblyName (name.Name);
584 // FIXME: examine all other parameters
586 AssemblyBuilder ab = new AssemblyBuilder (name, dir, access, false);
587 ab.AddPermissionRequests (requiredPermissions, optionalPermissions, refusedPermissions);
592 [Obsolete ("Declarative security for assembly level is no longer enforced")]
593 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
595 PermissionSet requiredPermissions,
596 PermissionSet optionalPermissions,
597 PermissionSet refusedPermissions, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
599 AssemblyBuilder ab = DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, isSynchronized);
600 if (assemblyAttributes != null)
601 foreach (CustomAttributeBuilder cb in assemblyAttributes) {
602 ab.SetCustomAttribute (cb);
608 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
610 return DefineDynamicAssembly (name, access, null, null, null, null, null, false, assemblyAttributes);
613 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
615 return DefineDynamicAssembly (name, access, dir, null, null, null, null, isSynchronized, assemblyAttributes);
618 [MonoLimitation ("The argument securityContextSource is ignored")]
619 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource)
621 return DefineDynamicAssembly (name, access, assemblyAttributes);
624 internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
626 return new AssemblyBuilder (name, null, access, true);
631 // AppDomain.DoCallBack works because AppDomain is a MarshalByRefObject
632 // so, when you call AppDomain.DoCallBack, that's a remote call
634 public void DoCallBack (CrossAppDomainDelegate callBackDelegate)
636 if (callBackDelegate != null)
640 public int ExecuteAssembly (string assemblyFile)
642 return ExecuteAssembly (assemblyFile, (Evidence)null, null);
645 [Obsolete ("Use an overload that does not take an Evidence parameter")]
646 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity)
648 return ExecuteAssembly (assemblyFile, assemblySecurity, null);
651 [Obsolete ("Use an overload that does not take an Evidence parameter")]
652 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args)
654 Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity);
655 return ExecuteAssemblyInternal (a, args);
658 [Obsolete ("Use an overload that does not take an Evidence parameter")]
659 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
661 Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity, hashValue, hashAlgorithm);
662 return ExecuteAssemblyInternal (a, args);
666 public int ExecuteAssembly (string assemblyFile, string[] args)
668 Assembly a = Assembly.LoadFrom (assemblyFile, null);
669 return ExecuteAssemblyInternal (a, args);
672 public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
674 Assembly a = Assembly.LoadFrom (assemblyFile, null, hashValue, hashAlgorithm);
675 return ExecuteAssemblyInternal (a, args);
678 int ExecuteAssemblyInternal (Assembly a, string[] args)
680 if (a.EntryPoint == null)
681 throw new MissingMethodException ("Entry point not found in assembly '" + a.FullName + "'.");
682 return ExecuteAssembly (a, args);
685 [MethodImplAttribute (MethodImplOptions.InternalCall)]
686 private extern int ExecuteAssembly (Assembly a, string[] args);
688 [MethodImplAttribute (MethodImplOptions.InternalCall)]
689 private extern Assembly [] GetAssemblies (bool refOnly);
691 public Assembly [] GetAssemblies ()
693 return GetAssemblies (false);
696 [MethodImplAttribute (MethodImplOptions.InternalCall)]
697 public extern object GetData (string name);
699 public new Type GetType()
701 return base.GetType ();
704 public override object InitializeLifetimeService ()
709 [MethodImplAttribute (MethodImplOptions.InternalCall)]
710 internal extern Assembly LoadAssembly (string assemblyRef, Evidence securityEvidence, bool refOnly);
712 public Assembly Load (AssemblyName assemblyRef)
714 return Load (assemblyRef, null);
717 internal Assembly LoadSatellite (AssemblyName assemblyRef, bool throwOnError)
719 if (assemblyRef == null)
720 throw new ArgumentNullException ("assemblyRef");
722 Assembly result = LoadAssembly (assemblyRef.FullName, null, false);
723 if (result == null && throwOnError)
724 throw new FileNotFoundException (null, assemblyRef.Name);
728 [Obsolete ("Use an overload that does not take an Evidence parameter")]
729 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
731 if (assemblyRef == null)
732 throw new ArgumentNullException ("assemblyRef");
734 if (assemblyRef.Name == null || assemblyRef.Name.Length == 0) {
735 if (assemblyRef.CodeBase != null)
736 return Assembly.LoadFrom (assemblyRef.CodeBase, assemblySecurity);
738 throw new ArgumentException (Locale.GetText ("assemblyRef.Name cannot be empty."), "assemblyRef");
741 Assembly assembly = LoadAssembly (assemblyRef.FullName, assemblySecurity, false);
742 if (assembly != null)
745 if (assemblyRef.CodeBase == null)
746 throw new FileNotFoundException (null, assemblyRef.Name);
748 string cb = assemblyRef.CodeBase;
749 if (cb.ToLower (CultureInfo.InvariantCulture).StartsWith ("file://"))
750 cb = new Mono.Security.Uri (cb).LocalPath;
753 assembly = Assembly.LoadFrom (cb, assemblySecurity);
755 throw new FileNotFoundException (null, assemblyRef.Name);
757 AssemblyName aname = assembly.GetName ();
758 // Name, version, culture, publickeytoken. Anything else?
759 if (assemblyRef.Name != aname.Name)
760 throw new FileNotFoundException (null, assemblyRef.Name);
762 if (assemblyRef.Version != null && assemblyRef.Version != new Version (0, 0, 0, 0) && assemblyRef.Version != aname.Version)
763 throw new FileNotFoundException (null, assemblyRef.Name);
765 if (assemblyRef.CultureInfo != null && assemblyRef.CultureInfo.Equals (aname))
766 throw new FileNotFoundException (null, assemblyRef.Name);
768 byte [] pt = assemblyRef.GetPublicKeyToken ();
769 if (pt != null && pt.Length != 0) {
770 byte [] loaded_pt = aname.GetPublicKeyToken ();
771 if (loaded_pt == null || (pt.Length != loaded_pt.Length))
772 throw new FileNotFoundException (null, assemblyRef.Name);
773 for (int i = pt.Length - 1; i >= 0; i--)
774 if (loaded_pt [i] != pt [i])
775 throw new FileNotFoundException (null, assemblyRef.Name);
780 public Assembly Load (string assemblyString)
782 return Load (assemblyString, null, false);
785 [Obsolete ("Use an overload that does not take an Evidence parameter")]
786 public Assembly Load (string assemblyString, Evidence assemblySecurity)
788 return Load (assemblyString, assemblySecurity, false);
791 internal Assembly Load (string assemblyString, Evidence assemblySecurity, bool refonly)
793 if (assemblyString == null)
794 throw new ArgumentNullException ("assemblyString");
796 if (assemblyString.Length == 0)
797 throw new ArgumentException ("assemblyString cannot have zero length");
799 Assembly assembly = LoadAssembly (assemblyString, assemblySecurity, refonly);
800 if (assembly == null)
801 throw new FileNotFoundException (null, assemblyString);
805 public Assembly Load (byte[] rawAssembly)
807 return Load (rawAssembly, null, null);
810 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
812 return Load (rawAssembly, rawSymbolStore, null);
815 [MethodImplAttribute (MethodImplOptions.InternalCall)]
816 internal extern Assembly LoadAssemblyRaw (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence, bool refonly);
818 [Obsolete ("Use an overload that does not take an Evidence parameter")]
819 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
821 return Load (rawAssembly, rawSymbolStore, securityEvidence, false);
824 internal Assembly Load (byte [] rawAssembly, byte [] rawSymbolStore, Evidence securityEvidence, bool refonly)
826 if (rawAssembly == null)
827 throw new ArgumentNullException ("rawAssembly");
829 Assembly assembly = LoadAssemblyRaw (rawAssembly, rawSymbolStore, securityEvidence, refonly);
830 assembly.FromByteArray = true;
833 [Obsolete ("AppDomain policy levels are obsolete")]
834 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
835 public void SetAppDomainPolicy (PolicyLevel domainPolicy)
837 if (domainPolicy == null)
838 throw new ArgumentNullException ("domainPolicy");
839 if (_granted != null) {
840 throw new PolicyException (Locale.GetText (
841 "An AppDomain policy is already specified."));
843 if (IsFinalizingForUnload ())
844 throw new AppDomainUnloadedException ();
846 PolicyStatement ps = domainPolicy.Resolve ((Evidence)_evidence);
847 _granted = ps.PermissionSet;
850 [Obsolete ("Use AppDomainSetup.SetCachePath")]
851 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
852 public void SetCachePath (string path)
854 SetupInformationNoCopy.CachePath = path;
857 [SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
858 public void SetPrincipalPolicy (PrincipalPolicy policy)
860 if (IsFinalizingForUnload ())
861 throw new AppDomainUnloadedException ();
864 _principalPolicy = (int)policy;
866 _principalPolicy = policy;
871 [Obsolete ("Use AppDomainSetup.ShadowCopyFiles")]
872 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
873 public void SetShadowCopyFiles()
875 SetupInformationNoCopy.ShadowCopyFiles = "true";
878 [Obsolete ("Use AppDomainSetup.ShadowCopyDirectories")]
879 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
880 public void SetShadowCopyPath (string path)
882 SetupInformationNoCopy.ShadowCopyDirectories = path;
885 [SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
886 public void SetThreadPrincipal (IPrincipal principal)
888 if (principal == null)
889 throw new ArgumentNullException ("principal");
890 if (_principal != null)
891 throw new PolicyException (Locale.GetText ("principal already present."));
892 if (IsFinalizingForUnload ())
893 throw new AppDomainUnloadedException ();
895 _principal = principal;
898 [MethodImplAttribute (MethodImplOptions.InternalCall)]
899 private static extern AppDomain InternalSetDomainByID (int domain_id);
901 // Changes the active domain and returns the old domain
902 [MethodImplAttribute (MethodImplOptions.InternalCall)]
903 private static extern AppDomain InternalSetDomain (AppDomain context);
905 // Notifies the runtime that this thread references 'domain'.
906 [MethodImplAttribute (MethodImplOptions.InternalCall)]
907 internal static extern void InternalPushDomainRef (AppDomain domain);
909 [MethodImplAttribute (MethodImplOptions.InternalCall)]
910 internal static extern void InternalPushDomainRefByID (int domain_id);
912 // Undoes the effect of the last PushDomainRef call
913 [MethodImplAttribute (MethodImplOptions.InternalCall)]
914 internal static extern void InternalPopDomainRef ();
916 // Changes the active context and returns the old context
917 [MethodImplAttribute (MethodImplOptions.InternalCall)]
918 internal static extern Context InternalSetContext (Context context);
920 // Returns the current context
921 [MethodImplAttribute (MethodImplOptions.InternalCall)]
922 internal static extern Context InternalGetContext ();
924 // Returns the current context
925 [MethodImplAttribute (MethodImplOptions.InternalCall)]
926 internal static extern Context InternalGetDefaultContext ();
928 [MethodImplAttribute (MethodImplOptions.InternalCall)]
929 internal static extern string InternalGetProcessGuid (string newguid);
931 // This method is handled specially by the runtime
932 // It is the only managed method which is allowed to set the current
934 internal static object InvokeInDomain (AppDomain domain, MethodInfo method, object obj, object [] args)
936 AppDomain current = CurrentDomain;
941 InternalPushDomainRef (domain);
943 InternalSetDomain (domain);
944 object o = ((MonoMethod) method).InternalInvoke (obj, args, out exc);
950 InternalSetDomain (current);
952 InternalPopDomainRef ();
956 internal static object InvokeInDomainByID (int domain_id, MethodInfo method, object obj, object [] args)
958 AppDomain current = CurrentDomain;
963 InternalPushDomainRefByID (domain_id);
965 InternalSetDomainByID (domain_id);
966 object o = ((MonoMethod) method).InternalInvoke (obj, args, out exc);
972 InternalSetDomain (current);
974 InternalPopDomainRef ();
978 internal static String GetProcessGuid ()
980 if (_process_guid == null) {
981 _process_guid = InternalGetProcessGuid (Guid.NewGuid().ToString ());
983 return _process_guid;
986 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
987 public static AppDomain CreateDomain (string friendlyName)
989 return CreateDomain (friendlyName, null, null);
992 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
994 return CreateDomain (friendlyName, securityInfo, null);
997 [MethodImplAttribute (MethodImplOptions.InternalCall)]
998 private static extern AppDomain createDomain (string friendlyName, AppDomainSetup info);
1000 [MonoLimitationAttribute ("Currently it does not allow the setup in the other domain")]
1001 [SecurityPermission (SecurityAction.Demand, ControlAppDomain = true)]
1002 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info)
1004 if (friendlyName == null)
1005 throw new System.ArgumentNullException ("friendlyName");
1007 AppDomain def = AppDomain.DefaultDomain;
1009 // if null, get default domain's SetupInformation
1011 info = new AppDomainSetup (); // we're default!
1013 info = def.SetupInformation;
1016 info = new AppDomainSetup (info); // copy
1018 // todo: allow setup in the other domain
1020 if (!info.Equals (def.SetupInformation)) {
1021 // If not specified use default domain's app base.
1022 if (info.ApplicationBase == null)
1023 info.ApplicationBase = def.SetupInformation.ApplicationBase;
1024 if (info.ConfigurationFile == null)
1025 info.ConfigurationFile = Path.GetFileName (def.SetupInformation.ConfigurationFile);
1027 } else if (info.ConfigurationFile == null)
1028 info.ConfigurationFile = "[I don't have a config file]";
1031 if (info.AppDomainInitializer != null) {
1032 if (!info.AppDomainInitializer.Method.IsStatic)
1033 throw new ArgumentException ("Non-static methods cannot be invoked as an appdomain initializer");
1037 info.SerializeNonPrimitives ();
1039 AppDomain ad = (AppDomain) RemotingServices.GetDomainProxy (createDomain (friendlyName, info));
1040 if (securityInfo == null) {
1041 // get default domain's Evidence (unless we're are the default!)
1043 ad._evidence = null; // we'll get them later (GetEntryAssembly)
1045 ad._evidence = def.Evidence; // new (shallow) copy
1048 ad._evidence = new Evidence (securityInfo); // copy
1051 if (info.AppDomainInitializer != null) {
1052 Loader loader = new Loader (
1053 info.AppDomainInitializer.Method.DeclaringType.Assembly.Location);
1054 ad.DoCallBack (loader.Load);
1056 Initializer initializer = new Initializer (
1057 info.AppDomainInitializer,
1058 info.AppDomainInitializerArguments);
1059 ad.DoCallBack (initializer.Initialize);
1066 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1067 public static AppDomain CreateDomain (string friendlyName)
1069 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1072 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1073 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
1075 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1078 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1079 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info)
1081 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1083 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1091 public Loader (string assembly)
1093 this.assembly = assembly;
1098 Assembly.LoadFrom (assembly);
1105 AppDomainInitializer initializer;
1106 string [] arguments;
1108 public Initializer (AppDomainInitializer initializer, string [] arguments)
1110 this.initializer = initializer;
1111 this.arguments = arguments;
1114 public void Initialize ()
1116 initializer (arguments);
1121 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1122 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,string appBasePath,
1123 string appRelativeSearchPath, bool shadowCopyFiles)
1125 return CreateDomain (friendlyName, securityInfo, CreateDomainSetup (appBasePath, appRelativeSearchPath, shadowCopyFiles));
1128 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1129 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,string appBasePath,
1130 string appRelativeSearchPath, bool shadowCopyFiles)
1132 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1134 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1137 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1138 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info,
1139 PermissionSet grantSet, params StrongName [] fullTrustAssemblies)
1142 throw new ArgumentNullException ("info");
1144 info.ApplicationTrust = new ApplicationTrust (grantSet, fullTrustAssemblies ?? EmptyArray<StrongName>.Value);
1145 return CreateDomain (friendlyName, securityInfo, info);
1148 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1149 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info,
1150 PermissionSet grantSet, params StrongName [] fullTrustAssemblies)
1152 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1154 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1157 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1158 static AppDomainSetup CreateDomainSetup (string appBasePath, string appRelativeSearchPath, bool shadowCopyFiles)
1160 AppDomainSetup info = new AppDomainSetup ();
1162 info.ApplicationBase = appBasePath;
1163 info.PrivateBinPath = appRelativeSearchPath;
1165 if (shadowCopyFiles)
1166 info.ShadowCopyFiles = "true";
1168 info.ShadowCopyFiles = "false";
1172 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1174 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1175 private static extern bool InternalIsFinalizingForUnload (int domain_id);
1177 public bool IsFinalizingForUnload()
1179 return InternalIsFinalizingForUnload (getDomainID ());
1182 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1183 static extern void InternalUnload (int domain_id);
1185 // We do this because if the domain is a transparant proxy this
1186 // will still return the correct domain id.
1187 private int getDomainID ()
1189 return Thread.GetDomainID ();
1192 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1193 [SecurityPermission (SecurityAction.Demand, ControlAppDomain = true)]
1194 [ReliabilityContractAttribute (Consistency.MayCorruptAppDomain, Cer.MayFail)]
1195 public static void Unload (AppDomain domain)
1198 throw new ArgumentNullException ("domain");
1200 InternalUnload (domain.getDomainID());
1203 [Obsolete ("AppDomain.Unload is not supported on the current platform.", true)]
1204 public static void Unload (AppDomain domain)
1206 throw new PlatformNotSupportedException ("AppDomain.Unload is not supported on the current platform.");
1208 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1210 [MethodImplAttribute (MethodImplOptions.InternalCall)]
1211 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1212 public extern void SetData (string name, object data);
1214 [MonoLimitation ("The permission field is ignored")]
1215 public void SetData (string name, object data, IPermission permission)
1217 SetData (name, data);
1221 [Obsolete ("Use AppDomainSetup.DynamicBase")]
1222 [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1223 public void SetDynamicBase (string path)
1225 SetupInformationNoCopy.DynamicBase = path;
1229 [Obsolete ("AppDomain.GetCurrentThreadId has been deprecated"
1230 + " because it does not provide a stable Id when managed"
1231 + " threads are running on fibers (aka lightweight"
1232 + " threads). To get a stable identifier for a managed"
1233 + " thread, use the ManagedThreadId property on Thread.'")]
1234 public static int GetCurrentThreadId ()
1236 return Thread.CurrentThreadId;
1239 public override string ToString ()
1241 return getFriendlyName ();
1244 private static void ValidateAssemblyName (string name)
1246 if (name == null || name.Length == 0)
1247 throw new ArgumentException ("The Name of " +
1248 "AssemblyName cannot be null or a " +
1249 "zero-length string.");
1251 bool isValid = true;
1253 for (int i = 0; i < name.Length; i++) {
1256 // do not allow leading whitespace
1257 if (i == 0 && char.IsWhiteSpace (c)) {
1262 // do not allow /,\ or : in name
1263 if (c == '/' || c == '\\' || c == ':') {
1270 throw new ArgumentException ("The Name of " +
1271 "AssemblyName cannot start with " +
1272 "whitespace, or contain '/', '\\' " +
1276 // The following methods are called from the runtime. Don't change signatures.
1277 #pragma warning disable 169
1278 private void DoAssemblyLoad (Assembly assembly)
1280 if (AssemblyLoad == null)
1283 AssemblyLoad (this, new AssemblyLoadEventArgs (assembly));
1286 private Assembly DoAssemblyResolve (string name, Assembly requestingAssembly, bool refonly)
1288 ResolveEventHandler del;
1291 del = ReflectionOnlyAssemblyResolve;
1293 del = AssemblyResolve;
1295 del = AssemblyResolve;
1300 /* Prevent infinite recursion */
1301 Dictionary<string, object> ht;
1303 ht = assembly_resolve_in_progress_refonly;
1305 ht = new Dictionary<string, object> ();
1306 assembly_resolve_in_progress_refonly = ht;
1309 ht = assembly_resolve_in_progress;
1311 ht = new Dictionary<string, object> ();
1312 assembly_resolve_in_progress = ht;
1316 if (ht.ContainsKey (name))
1321 Delegate[] invocation_list = del.GetInvocationList ();
1323 foreach (Delegate eh in invocation_list) {
1324 ResolveEventHandler handler = (ResolveEventHandler) eh;
1325 Assembly assembly = handler (this, new ResolveEventArgs (name, requestingAssembly));
1326 if (assembly != null)
1336 internal Assembly DoTypeResolve (Object name_or_tb)
1338 if (TypeResolve == null)
1343 #if !FULL_AOT_RUNTIME
1344 if (name_or_tb is TypeBuilder)
1345 name = ((TypeBuilder) name_or_tb).FullName;
1348 name = (string) name_or_tb;
1350 /* Prevent infinite recursion */
1351 var ht = type_resolve_in_progress;
1353 type_resolve_in_progress = ht = new Dictionary<string, object> ();
1356 if (ht.ContainsKey (name))
1362 foreach (Delegate d in TypeResolve.GetInvocationList ()) {
1363 ResolveEventHandler eh = (ResolveEventHandler) d;
1364 Assembly assembly = eh (this, new ResolveEventArgs (name));
1365 if (assembly != null)
1375 internal Assembly DoResourceResolve (string name, Assembly requesting) {
1376 if (ResourceResolve == null)
1379 Delegate[] invocation_list = ResourceResolve.GetInvocationList ();
1381 foreach (Delegate eh in invocation_list) {
1382 ResolveEventHandler handler = (ResolveEventHandler) eh;
1383 Assembly assembly = handler (this, new ResolveEventArgs (name, requesting));
1384 if (assembly != null)
1390 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1391 private void DoDomainUnload ()
1393 if (DomainUnload != null)
1394 DomainUnload(this, null);
1396 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1398 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1399 internal extern void DoUnhandledException (Exception e);
1401 internal void DoUnhandledException (UnhandledExceptionEventArgs args) {
1402 if (UnhandledException != null)
1403 UnhandledException (this, args);
1406 internal byte[] GetMarshalledDomainObjRef ()
1408 ObjRef oref = RemotingServices.Marshal (AppDomain.CurrentDomain, null, typeof (AppDomain));
1409 return CADSerializer.SerializeObject (oref).GetBuffer();
1412 internal void ProcessMessageInDomain (byte[] arrRequest, CADMethodCallMessage cadMsg,
1413 out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
1417 if (null != arrRequest)
1418 reqDomMsg = CADSerializer.DeserializeMessage (new MemoryStream(arrRequest), null);
1420 reqDomMsg = new MethodCall (cadMsg);
1422 IMessage retDomMsg = ChannelServices.SyncDispatchMessage (reqDomMsg);
1424 cadMrm = CADMethodReturnMessage.Create (retDomMsg);
1425 if (null == cadMrm) {
1426 arrResponse = CADSerializer.SerializeMessage (retDomMsg).GetBuffer();
1432 #pragma warning restore 169
1434 // End of methods called from the runtime
1436 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1437 public event AssemblyLoadEventHandler AssemblyLoad;
1439 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1440 public event ResolveEventHandler AssemblyResolve;
1442 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1443 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1445 [Obsolete ("AppDomain.DomainUnload is not supported on the current platform.", true)]
1446 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1447 public event EventHandler DomainUnload;
1449 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1450 public event EventHandler ProcessExit;
1452 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1453 public event ResolveEventHandler ResourceResolve;
1455 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1456 public event ResolveEventHandler TypeResolve;
1458 [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
1459 public event UnhandledExceptionEventHandler UnhandledException;
1461 public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException;
1464 public bool IsHomogenous {
1465 get { return true; }
1469 public bool IsFullyTrusted {
1470 get { return true; }
1473 #pragma warning disable 649
1475 private AppDomainManager _domain_manager;
1477 object _domain_manager;
1479 #pragma warning restore 649
1481 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1483 public AppDomainManager DomainManager {
1484 get { return (AppDomainManager)_domain_manager; }
1487 [Obsolete ("AppDomain.DomainManager is not supported on this platform.", true)]
1488 public AppDomainManager DomainManager {
1489 get { throw new PlatformNotSupportedException ("AppDomain.DomainManager is not supported on this platform."); }
1491 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1494 public event ResolveEventHandler ReflectionOnlyAssemblyResolve;
1497 #pragma warning disable 649
1499 private object _activation;
1500 private object _applicationIdentity;
1502 private ActivationContext _activation;
1503 private ApplicationIdentity _applicationIdentity;
1505 #pragma warning restore 649
1509 public ActivationContext ActivationContext {
1510 get { return (ActivationContext)_activation; }
1513 public ApplicationIdentity ApplicationIdentity {
1514 get { return (ApplicationIdentity)_applicationIdentity; }
1518 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
1519 get { return getDomainID (); }
1524 [MonoTODO ("This routine only returns the parameter currently")]
1525 [ComVisible (false)]
1526 public string ApplyPolicy (string assemblyName)
1528 if (assemblyName == null)
1529 throw new ArgumentNullException ("assemblyName");
1530 if (assemblyName.Length == 0) // String.Empty
1531 throw new ArgumentException ("assemblyName");
1532 return assemblyName;
1537 #if MONO_FEATURE_MULTIPLE_APPDOMAINS
1538 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, string appBasePath,
1539 string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
1541 AppDomainSetup info = CreateDomainSetup (appBasePath, appRelativeSearchPath, shadowCopyFiles);
1543 info.AppDomainInitializerArguments = adInitArgs;
1544 info.AppDomainInitializer = adInit;
1546 return CreateDomain (friendlyName, securityInfo, info);
1549 [Obsolete ("AppDomain.CreateDomain is not supported on the current platform.", true)]
1550 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, string appBasePath,
1551 string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
1553 throw new PlatformNotSupportedException ("AppDomain.CreateDomain is not supported on the current platform.");
1555 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
1557 public int ExecuteAssemblyByName (string assemblyName)
1559 return ExecuteAssemblyByName (assemblyName, (Evidence)null, null);
1562 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1563 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity)
1565 return ExecuteAssemblyByName (assemblyName, assemblySecurity, null);
1568 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1569 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity, params string[] args)
1571 Assembly a = Assembly.Load (assemblyName, assemblySecurity);
1573 return ExecuteAssemblyInternal (a, args);
1576 [Obsolete ("Use an overload that does not take an Evidence parameter")]
1577 public int ExecuteAssemblyByName (AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
1579 Assembly a = Assembly.Load (assemblyName, assemblySecurity);
1581 return ExecuteAssemblyInternal (a, args);
1584 public int ExecuteAssemblyByName (string assemblyName, params string[] args)
1586 Assembly a = Assembly.Load (assemblyName, null);
1588 return ExecuteAssemblyInternal (a, args);
1591 public int ExecuteAssemblyByName (AssemblyName assemblyName, params string[] args)
1593 Assembly a = Assembly.Load (assemblyName, null);
1595 return ExecuteAssemblyInternal (a, args);
1598 public bool IsDefaultAppDomain ()
1600 return Object.ReferenceEquals (this, DefaultDomain);
1603 public Assembly[] ReflectionOnlyGetAssemblies ()
1605 return GetAssemblies (true);
1609 void _AppDomain.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1611 throw new NotImplementedException ();
1614 void _AppDomain.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1616 throw new NotImplementedException ();
1619 void _AppDomain.GetTypeInfoCount (out uint pcTInfo)
1621 throw new NotImplementedException ();
1624 void _AppDomain.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams,
1625 IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1627 throw new NotImplementedException ();
1631 List<string> compatibility_switch;
1633 public bool? IsCompatibilitySwitchSet (string value)
1636 throw new ArgumentNullException ("value");
1638 // default (at least for SL4) is to return false for unknown values (can't get a null out of it)
1639 return ((compatibility_switch != null) && compatibility_switch.Contains (value));
1642 internal void SetCompatibilitySwitch (string value)
1644 if (compatibility_switch == null)
1645 compatibility_switch = new List<string> ();
1646 compatibility_switch.Add (value);
1649 [MonoTODO ("Currently always returns false")]
1650 public static bool MonitoringIsEnabled {
1651 get { return false; }
1652 set { throw new NotImplementedException (); }
1656 public long MonitoringSurvivedMemorySize {
1657 get { throw new NotImplementedException (); }
1661 public static long MonitoringSurvivedProcessMemorySize {
1662 get { throw new NotImplementedException (); }
1666 public long MonitoringTotalAllocatedMemorySize {
1667 get { throw new NotImplementedException (); }
1671 public TimeSpan MonitoringTotalProcessorTime {
1672 get { throw new NotImplementedException (); }