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 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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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;
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;
55 [ClassInterface(ClassInterfaceType.None)]
56 public sealed class AppDomain : MarshalByRefObject , _AppDomain , IEvidenceFactory
58 IntPtr _mono_app_domain;
59 static string _process_guid;
62 static Hashtable type_resolve_in_progress;
65 static Hashtable assembly_resolve_in_progress;
68 private Evidence _evidence;
69 private PermissionSet _granted;
70 internal PermissionSet _refused;
73 private PrincipalPolicy _principalPolicy;
76 private static IPrincipal _principal;
82 [MethodImplAttribute (MethodImplOptions.InternalCall)]
83 private extern AppDomainSetup getSetup ();
85 AppDomainSetup SetupInformationNoCopy {
86 get { return getSetup (); }
89 public AppDomainSetup SetupInformation {
91 AppDomainSetup setup = getSetup ();
92 return new AppDomainSetup (setup);
96 public string BaseDirectory {
98 return SetupInformationNoCopy.ApplicationBase;
102 public string RelativeSearchPath {
104 return SetupInformationNoCopy.PrivateBinPath;
108 public string DynamicDirectory {
110 AppDomainSetup setup = SetupInformationNoCopy;
111 if (setup.DynamicBase == null) return null;
112 return Path.Combine (setup.DynamicBase, setup.ApplicationName);
116 public bool ShadowCopyFiles {
118 return (SetupInformationNoCopy.ShadowCopyFiles == "true");
122 [MethodImplAttribute (MethodImplOptions.InternalCall)]
123 private extern string getFriendlyName ();
125 public string FriendlyName {
127 return getFriendlyName ();
131 public Evidence Evidence {
133 // if the host (runtime) hasn't provided it's own evidence...
134 if (_evidence == null) {
135 // ... we will provide our own
137 // the executed assembly from the "default" appdomain
138 // or null if we're not in the default appdomain
139 Assembly a = Assembly.GetEntryAssembly ();
141 _evidence = AppDomain.DefaultDomain.Evidence;
143 _evidence = Evidence.GetDefaultHostEvidence (a);
146 return new Evidence (_evidence); // return a copy
150 internal IPrincipal DefaultPrincipal {
152 if (_principal == null) {
153 switch (_principalPolicy) {
154 case PrincipalPolicy.UnauthenticatedPrincipal:
155 _principal = new GenericPrincipal (
156 new GenericIdentity (String.Empty, String.Empty), null);
158 case PrincipalPolicy.WindowsPrincipal:
159 _principal = new WindowsPrincipal (WindowsIdentity.GetCurrent ());
167 [MethodImplAttribute (MethodImplOptions.InternalCall)]
168 private static extern AppDomain getCurDomain ();
170 public static AppDomain CurrentDomain {
172 return getCurDomain ();
176 [MethodImplAttribute (MethodImplOptions.InternalCall)]
177 private static extern AppDomain getRootDomain ();
179 internal static AppDomain DefaultDomain {
181 return getRootDomain ();
188 public void AppendPrivatePath (string path)
190 if (path == null || path.Length == 0)
193 AppDomainSetup setup = SetupInformationNoCopy;
195 string pp = setup.PrivateBinPath;
196 if (pp == null || pp.Length == 0) {
197 setup.PrivateBinPath = path;
202 if (pp [pp.Length - 1] != Path.PathSeparator)
203 pp += Path.PathSeparator;
205 setup.PrivateBinPath = pp + path;
211 public void ClearPrivatePath ()
213 SetupInformationNoCopy.PrivateBinPath = String.Empty;
216 public void ClearShadowCopyPath ()
218 SetupInformationNoCopy.ShadowCopyDirectories = String.Empty;
221 public ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName)
223 return Activator.CreateComInstanceFrom (assemblyName, typeName);
227 public static ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName,
228 byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
230 return Activator.CreateComInstanceFrom (assemblyName, typeName, hashValue ,hashAlgorithm);
234 public ObjectHandle CreateInstance (string assemblyName, string typeName)
236 if (assemblyName == null)
237 throw new ArgumentNullException ("assemblyName");
239 return Activator.CreateInstance (assemblyName, typeName);
242 public ObjectHandle CreateInstance (string assemblyName, string typeName, object[] activationAttributes)
244 if (assemblyName == null)
245 throw new ArgumentNullException ("assemblyName");
247 return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
250 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
251 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes,
252 Evidence securityAttributes)
254 if (assemblyName == null)
255 throw new ArgumentNullException ("assemblyName");
257 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
258 culture, activationAttributes, securityAttributes);
261 public object CreateInstanceAndUnwrap (string assemblyName, string typeName)
263 ObjectHandle oh = CreateInstance (assemblyName, typeName);
264 return (oh != null) ? oh.Unwrap () : null;
267 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
269 ObjectHandle oh = CreateInstance (assemblyName, typeName, activationAttributes);
270 return (oh != null) ? oh.Unwrap () : null;
273 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
274 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
275 object[] activationAttributes, Evidence securityAttributes)
277 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
278 culture, activationAttributes, securityAttributes);
279 return (oh != null) ? oh.Unwrap () : null;
282 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName)
284 if (assemblyName == null)
285 throw new ArgumentNullException ("assemblyName");
287 return Activator.CreateInstanceFrom (assemblyName, typeName);
290 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName, object[] activationAttributes)
292 if (assemblyName == null)
293 throw new ArgumentNullException ("assemblyName");
295 return Activator.CreateInstanceFrom (assemblyName, typeName, activationAttributes);
298 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName, bool ignoreCase,
299 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
300 object[] activationAttributes, Evidence securityAttributes)
302 if (assemblyName == null)
303 throw new ArgumentNullException ("assemblyName");
305 return Activator.CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
306 culture, activationAttributes, securityAttributes);
309 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName)
311 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName);
312 return (oh != null) ? oh.Unwrap () : null;
315 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
317 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, activationAttributes);
318 return (oh != null) ? oh.Unwrap () : null;
321 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
322 BindingFlags bindingAttr, Binder binder, object[] args,
323 CultureInfo culture, object[] activationAttributes,
324 Evidence securityAttributes)
326 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
327 culture, activationAttributes, securityAttributes);
329 return (oh != null) ? oh.Unwrap () : null;
332 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
334 return DefineDynamicAssembly (name, access, null, null, null, null, null, false);
337 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
339 return DefineDynamicAssembly (name, access, null, evidence, null, null, null, false);
342 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir)
344 return DefineDynamicAssembly (name, access, dir, null, null, null, null, false);
347 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
350 return DefineDynamicAssembly (name, access, dir, evidence, null, null, null, false);
353 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access,
354 PermissionSet requiredPermissions,
355 PermissionSet optionalPermissions,
356 PermissionSet refusedPermissions)
358 return DefineDynamicAssembly (name, access, null, null, requiredPermissions, optionalPermissions,
359 refusedPermissions, false);
362 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
363 PermissionSet requiredPermissions,
364 PermissionSet optionalPermissions,
365 PermissionSet refusedPermissions)
367 return DefineDynamicAssembly (name, access, null, evidence, requiredPermissions, optionalPermissions,
368 refusedPermissions, false);
371 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
372 PermissionSet requiredPermissions,
373 PermissionSet optionalPermissions,
374 PermissionSet refusedPermissions)
376 return DefineDynamicAssembly (name, access, dir, null, requiredPermissions, optionalPermissions,
377 refusedPermissions, false);
380 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
382 PermissionSet requiredPermissions,
383 PermissionSet optionalPermissions,
384 PermissionSet refusedPermissions)
386 return DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions,
387 refusedPermissions, false);
390 [MonoTODO ("FIXME: examine all other parameters")]
391 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
393 PermissionSet requiredPermissions,
394 PermissionSet optionalPermissions,
395 PermissionSet refusedPermissions, bool isSynchronized)
397 // FIXME: examine all other parameters
399 AssemblyBuilder ab = new AssemblyBuilder (name, dir, access, false);
400 ab.AddPermissionRequests (requiredPermissions, optionalPermissions, refusedPermissions);
404 internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
406 return new AssemblyBuilder (name, null, access, true);
409 public void DoCallBack (CrossAppDomainDelegate theDelegate)
411 if (theDelegate != null)
415 public int ExecuteAssembly (string assemblyFile)
417 return ExecuteAssembly (assemblyFile, null, null);
420 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity)
422 return ExecuteAssembly (assemblyFile, assemblySecurity, null);
425 [MethodImplAttribute (MethodImplOptions.InternalCall)]
426 public extern int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args);
429 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
431 throw new NotImplementedException ();
434 [MethodImplAttribute (MethodImplOptions.InternalCall)]
435 public extern Assembly [] GetAssemblies ();
437 [MethodImplAttribute (MethodImplOptions.InternalCall)]
438 public extern object GetData (string name);
440 public new Type GetType()
442 return base.GetType ();
445 public override object InitializeLifetimeService ()
450 [MethodImplAttribute (MethodImplOptions.InternalCall)]
451 private extern Assembly LoadAssembly (string assemblyRef, Evidence securityEvidence);
453 public Assembly Load (AssemblyName assemblyRef)
455 return Load (assemblyRef, null);
458 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
460 if (assemblyRef == null)
461 throw new ArgumentNullException ("assemblyRef");
463 if (assemblyRef.Name == null || assemblyRef.Name.Length == 0) {
464 if (assemblyRef.CodeBase != null)
465 return Assembly.LoadFrom (assemblyRef.CodeBase, assemblySecurity);
467 throw new ArgumentException (Locale.GetText ("assemblyRef.Name cannot be empty."), "assemblyRef");
470 return LoadAssembly (assemblyRef.FullName, assemblySecurity);
473 public Assembly Load (string assemblyString)
475 if (assemblyString == null)
476 throw new ArgumentNullException ("assemblyString");
478 return LoadAssembly (assemblyString, null);
481 public Assembly Load (string assemblyString, Evidence assemblySecurity)
483 if (assemblyString == null)
484 throw new ArgumentNullException ("assemblyString");
486 return LoadAssembly (assemblyString, assemblySecurity);
489 public Assembly Load (byte[] rawAssembly)
491 return Load (rawAssembly, null, null);
494 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
496 return Load (rawAssembly, rawSymbolStore, null);
499 [MethodImplAttribute (MethodImplOptions.InternalCall)]
500 private extern Assembly LoadAssemblyRaw (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence);
502 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
504 if (rawAssembly == null)
505 throw new ArgumentNullException ("rawAssembly");
507 return LoadAssemblyRaw (rawAssembly, rawSymbolStore, securityEvidence);
510 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
511 public void SetAppDomainPolicy (PolicyLevel domainPolicy)
513 if (domainPolicy == null)
514 throw new ArgumentNullException ("domainPolicy");
515 if (_granted != null) {
516 throw new PolicyException (Locale.GetText (
517 "An AppDomain policy is already specified."));
519 if (IsFinalizingForUnload ())
520 throw new AppDomainUnloadedException ();
522 _granted = SecurityManager.ResolvePolicy (_evidence);
525 public void SetCachePath (string path)
527 SetupInformationNoCopy.CachePath = path;
530 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
531 public void SetPrincipalPolicy (PrincipalPolicy policy)
533 if (IsFinalizingForUnload ())
534 throw new AppDomainUnloadedException ();
536 _principalPolicy = policy;
540 public void SetShadowCopyFiles()
542 SetupInformationNoCopy.ShadowCopyFiles = "true";
545 public void SetShadowCopyPath (string path)
547 SetupInformationNoCopy.ShadowCopyDirectories = path;
550 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
551 public void SetThreadPrincipal (IPrincipal principal)
553 if (principal == null)
554 throw new ArgumentNullException ("principal");
555 if (_principal != null)
556 throw new PolicyException (Locale.GetText ("principal already present."));
557 if (IsFinalizingForUnload ())
558 throw new AppDomainUnloadedException ();
560 _principal = principal;
563 [MethodImplAttribute (MethodImplOptions.InternalCall)]
564 private static extern AppDomain InternalSetDomainByID (int domain_id);
566 // Changes the active domain and returns the old domain
567 [MethodImplAttribute (MethodImplOptions.InternalCall)]
568 private static extern AppDomain InternalSetDomain (AppDomain context);
570 // Notifies the runtime that this thread references 'domain'.
571 [MethodImplAttribute (MethodImplOptions.InternalCall)]
572 internal static extern void InternalPushDomainRef (AppDomain domain);
574 [MethodImplAttribute (MethodImplOptions.InternalCall)]
575 internal static extern void InternalPushDomainRefByID (int domain_id);
577 // Undoes the effect of the last PushDomainRef call
578 [MethodImplAttribute (MethodImplOptions.InternalCall)]
579 internal static extern void InternalPopDomainRef ();
581 // Changes the active context and returns the old context
582 [MethodImplAttribute (MethodImplOptions.InternalCall)]
583 internal static extern Context InternalSetContext (Context context);
585 // Returns the current context
586 [MethodImplAttribute (MethodImplOptions.InternalCall)]
587 internal static extern Context InternalGetContext ();
589 // Returns the current context
590 [MethodImplAttribute (MethodImplOptions.InternalCall)]
591 internal static extern Context InternalGetDefaultContext ();
593 [MethodImplAttribute (MethodImplOptions.InternalCall)]
594 internal static extern string InternalGetProcessGuid (string newguid);
596 // This method is handled specially by the runtime
597 // It is the only managed method which is allowed to set the current
599 internal static object InvokeInDomain (AppDomain domain, MethodInfo method, object obj, object [] args)
601 AppDomain current = CurrentDomain;
605 InternalPushDomainRef (domain);
607 InternalSetDomain (domain);
608 return ((MonoMethod) method).InternalInvoke (obj, args);
611 InternalSetDomain (current);
613 InternalPopDomainRef ();
617 internal static object InvokeInDomainByID (int domain_id, MethodInfo method, object obj, object [] args)
619 AppDomain current = CurrentDomain;
623 InternalPushDomainRefByID (domain_id);
625 InternalSetDomainByID (domain_id);
626 return ((MonoMethod) method).InternalInvoke (obj, args);
629 InternalSetDomain (current);
631 InternalPopDomainRef ();
635 internal static String GetProcessGuid ()
637 if (_process_guid == null) {
638 _process_guid = InternalGetProcessGuid (Guid.NewGuid().ToString ());
640 return _process_guid;
643 public static AppDomain CreateDomain (string friendlyName)
645 return CreateDomain (friendlyName, null, null);
648 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
650 return CreateDomain (friendlyName, securityInfo, null);
653 [MethodImplAttribute (MethodImplOptions.InternalCall)]
654 private static extern AppDomain createDomain (string friendlyName, AppDomainSetup info);
656 [MonoTODO ("allow setup in the other domain")]
657 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info)
659 if (friendlyName == null)
660 throw new System.ArgumentNullException ("friendlyName");
663 // if null, get default domain's SetupInformation
664 AppDomain def = AppDomain.DefaultDomain;
666 info = new AppDomainSetup (); // we're default!
668 info = def.SetupInformation;
671 info = new AppDomainSetup (info); // copy
673 // todo: allow setup in the other domain
675 AppDomain ad = (AppDomain) RemotingServices.GetDomainProxy (createDomain (friendlyName, info));
676 if (securityInfo == null) {
677 // get default domain's Evidence (unless we're are the default!)
678 AppDomain def = AppDomain.DefaultDomain;
680 ad._evidence = null; // we'll get them later (GetEntryAssembly)
682 ad._evidence = def.Evidence; // new (shallow) copy
685 ad._evidence = new Evidence (securityInfo); // copy
690 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,string appBasePath,
691 string appRelativeSearchPath, bool shadowCopyFiles)
693 AppDomainSetup info = new AppDomainSetup ();
695 info.ApplicationBase = appBasePath;
696 info.PrivateBinPath = appRelativeSearchPath;
699 info.ShadowCopyFiles = "true";
701 info.ShadowCopyFiles = "false";
703 return CreateDomain (friendlyName, securityInfo, info);
706 [MethodImplAttribute (MethodImplOptions.InternalCall)]
707 private static extern bool InternalIsFinalizingForUnload (int domain_id);
709 public bool IsFinalizingForUnload()
711 return InternalIsFinalizingForUnload (getDomainID ());
714 [MethodImplAttribute (MethodImplOptions.InternalCall)]
715 static extern void InternalUnload (int domain_id);
717 // We do this because if the domain is a transparant proxy this
718 // will still return the correct domain id.
719 private int getDomainID ()
721 return Thread.GetDomainID ();
724 public static void Unload (AppDomain domain)
727 throw new ArgumentNullException ("domain");
729 InternalUnload (domain.getDomainID());
732 [MethodImplAttribute (MethodImplOptions.InternalCall)]
733 public extern void SetData (string name, object data);
735 public void SetDynamicBase (string path)
737 SetupInformationNoCopy.DynamicBase = path;
743 public static int GetCurrentThreadId ()
745 return Thread.CurrentThreadId;
748 public override string ToString ()
750 return getFriendlyName ();
753 // The following methods are called from the runtime. Don't change signatures.
754 private void DoAssemblyLoad (Assembly assembly)
756 if (AssemblyLoad == null)
759 AssemblyLoad (this, new AssemblyLoadEventArgs (assembly));
762 private Assembly DoAssemblyResolve (string name)
764 if (AssemblyResolve == null)
767 /* Prevent infinite recursion */
768 Hashtable ht = assembly_resolve_in_progress;
770 ht = new Hashtable ();
771 assembly_resolve_in_progress = ht;
774 if (ht.Contains (name))
780 foreach (Delegate eh in AssemblyResolve.GetInvocationList ()) {
781 ResolveEventHandler handler = (ResolveEventHandler) eh;
782 Assembly assembly = handler (this, new ResolveEventArgs (name));
783 if (assembly != null)
793 internal Assembly DoTypeResolve (Object name_or_tb)
795 if (TypeResolve == null)
800 if (name_or_tb is TypeBuilder)
801 name = ((TypeBuilder) name_or_tb).FullName;
803 name = (string) name_or_tb;
805 /* Prevent infinite recursion */
806 Hashtable ht = type_resolve_in_progress;
808 ht = new Hashtable ();
809 type_resolve_in_progress = ht;
812 if (ht.Contains (name))
818 foreach (Delegate d in TypeResolve.GetInvocationList ()) {
819 ResolveEventHandler eh = (ResolveEventHandler) d;
820 Assembly assembly = eh (this, new ResolveEventArgs (name));
821 if (assembly != null)
831 private void DoDomainUnload ()
833 if (DomainUnload != null)
834 DomainUnload(this, null);
837 internal byte[] GetMarshalledDomainObjRef ()
839 ObjRef oref = RemotingServices.Marshal (AppDomain.CurrentDomain, null, typeof (AppDomain));
840 return CADSerializer.SerializeObject (oref).GetBuffer();
843 internal void ProcessMessageInDomain (byte[] arrRequest, CADMethodCallMessage cadMsg,
844 out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
848 if (null != arrRequest)
849 reqDomMsg = CADSerializer.DeserializeMessage (new MemoryStream(arrRequest), null);
851 reqDomMsg = new MethodCall (cadMsg);
853 IMessage retDomMsg = ChannelServices.SyncDispatchMessage (reqDomMsg);
855 cadMrm = CADMethodReturnMessage.Create (retDomMsg);
856 if (null == cadMrm) {
857 arrResponse = CADSerializer.SerializeMessage (retDomMsg).GetBuffer();
863 // End of methods called from the runtime
865 public event AssemblyLoadEventHandler AssemblyLoad;
867 public event ResolveEventHandler AssemblyResolve;
869 public event EventHandler DomainUnload;
871 public event EventHandler ProcessExit;
873 public event ResolveEventHandler ResourceResolve;
875 public event ResolveEventHandler TypeResolve;
877 public event UnhandledExceptionEventHandler UnhandledException;
880 private ActivationContext _activation;
881 private ApplicationIdentity _applicationIdentity;
882 private AppDomainManager _domain_manager;
886 public ActivationContext ActivationContext {
887 get { return _activation; }
890 public ApplicationIdentity ApplicationIdentity {
891 get { return _applicationIdentity; }
895 public AppDomainManager DomainManager {
896 get { return _domain_manager; }
900 get { return getDomainID (); }
905 [MonoTODO ("what's the policy affecting names ?")]
907 public string ApplyPolicy (string assemblyName)
909 if (assemblyName == null)
910 throw new ArgumentNullException ("assemblyName");
911 if (assemblyName.Length == 0) // String.Empty
912 throw new ArgumentException ("assemblyName");
918 [MonoTODO ("add support for new delegate")]
919 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, string appBasePath,
920 string appRelativeSearchPath, bool shadowCopy, AppDomainInitializer adInit, string[] adInitArgs)
922 return CreateDomain (friendlyName, securityInfo, appBasePath, appRelativeSearchPath, shadowCopy);
925 [MonoTODO ("resolve assemblyName to location")]
926 public int ExecuteAssemblyByName (string assemblyName)
928 return ExecuteAssemblyByName (assemblyName, null, null);
931 [MonoTODO ("resolve assemblyName to location")]
932 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity)
934 return ExecuteAssemblyByName (assemblyName, assemblySecurity, null);
937 [MonoTODO ("resolve assemblyName to location")]
938 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity, string[] args)
940 if (assemblyName == null)
941 throw new ArgumentNullException ("assemblyName");
943 AssemblyName an = new AssemblyName (assemblyName);
944 return ExecuteAssemblyByName (an, assemblySecurity, args);
947 [MonoTODO ("assemblyName may not have a codebase")]
948 public int ExecuteAssemblyByName (AssemblyName assemblyName, Evidence assemblySecurity, string[] args)
950 if (assemblyName == null)
951 throw new ArgumentNullException ("assemblyName");
953 return ExecuteAssembly (assemblyName.CodeBase, assemblySecurity, args);
956 public bool IsDefaultAppDomain ()
958 return Object.ReferenceEquals (this, DefaultDomain);
961 [MonoTODO ("see Assembly.ReflectionOnlyLoad")]
962 public Assembly[] ReflectionOnlyGetAssemblies ()
964 return new Assembly [0];