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 // Get an AppDomain by it's ID (required to find the "default" app domain)
177 [MethodImplAttribute (MethodImplOptions.InternalCall)]
178 private static extern AppDomain getDomainByID (int domain_id);
180 internal static AppDomain DefaultDomain {
182 return getDomainByID (0);
189 public void AppendPrivatePath (string path)
191 if (path == null || path.Length == 0)
194 AppDomainSetup setup = SetupInformationNoCopy;
196 string pp = setup.PrivateBinPath;
197 if (pp == null || pp.Length == 0) {
198 setup.PrivateBinPath = path;
203 if (pp [pp.Length - 1] != Path.PathSeparator)
204 pp += Path.PathSeparator;
206 setup.PrivateBinPath = pp + path;
212 public void ClearPrivatePath ()
214 SetupInformationNoCopy.PrivateBinPath = String.Empty;
217 public void ClearShadowCopyPath ()
219 SetupInformationNoCopy.ShadowCopyDirectories = String.Empty;
222 public ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName)
224 return Activator.CreateComInstanceFrom (assemblyName, typeName);
228 public static ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName,
229 byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
231 return Activator.CreateComInstanceFrom (assemblyName, typeName, hashValue ,hashAlgorithm);
235 public ObjectHandle CreateInstance (string assemblyName, string typeName)
237 if (assemblyName == null)
238 throw new ArgumentNullException ("assemblyName");
240 return Activator.CreateInstance (assemblyName, typeName);
243 public ObjectHandle CreateInstance (string assemblyName, string typeName, object[] activationAttributes)
245 if (assemblyName == null)
246 throw new ArgumentNullException ("assemblyName");
248 return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
251 public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
252 Binder binder, object[] args, CultureInfo culture, object[] activationAttributes,
253 Evidence securityAttributes)
255 if (assemblyName == null)
256 throw new ArgumentNullException ("assemblyName");
258 return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
259 culture, activationAttributes, securityAttributes);
262 public object CreateInstanceAndUnwrap (string assemblyName, string typeName)
264 ObjectHandle oh = CreateInstance (assemblyName, typeName);
265 return (oh != null) ? oh.Unwrap () : null;
268 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
270 ObjectHandle oh = CreateInstance (assemblyName, typeName, activationAttributes);
271 return (oh != null) ? oh.Unwrap () : null;
274 public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
275 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
276 object[] activationAttributes, Evidence securityAttributes)
278 ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
279 culture, activationAttributes, securityAttributes);
280 return (oh != null) ? oh.Unwrap () : null;
283 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName)
285 if (assemblyName == null)
286 throw new ArgumentNullException ("assemblyName");
288 return Activator.CreateInstanceFrom (assemblyName, typeName);
291 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName, object[] activationAttributes)
293 if (assemblyName == null)
294 throw new ArgumentNullException ("assemblyName");
296 return Activator.CreateInstanceFrom (assemblyName, typeName, activationAttributes);
299 public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName, bool ignoreCase,
300 BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
301 object[] activationAttributes, Evidence securityAttributes)
303 if (assemblyName == null)
304 throw new ArgumentNullException ("assemblyName");
306 return Activator.CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
307 culture, activationAttributes, securityAttributes);
310 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName)
312 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName);
313 return (oh != null) ? oh.Unwrap () : null;
316 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, object [] activationAttributes)
318 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, activationAttributes);
319 return (oh != null) ? oh.Unwrap () : null;
322 public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
323 BindingFlags bindingAttr, Binder binder, object[] args,
324 CultureInfo culture, object[] activationAttributes,
325 Evidence securityAttributes)
327 ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
328 culture, activationAttributes, securityAttributes);
330 return (oh != null) ? oh.Unwrap () : null;
333 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
335 return DefineDynamicAssembly (name, access, null, null, null, null, null, false);
338 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
340 return DefineDynamicAssembly (name, access, null, evidence, null, null, null, false);
343 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir)
345 return DefineDynamicAssembly (name, access, dir, null, null, null, null, false);
348 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
351 return DefineDynamicAssembly (name, access, dir, evidence, null, null, null, false);
354 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access,
355 PermissionSet requiredPermissions,
356 PermissionSet optionalPermissions,
357 PermissionSet refusedPermissions)
359 return DefineDynamicAssembly (name, access, null, null, requiredPermissions, optionalPermissions,
360 refusedPermissions, false);
363 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
364 PermissionSet requiredPermissions,
365 PermissionSet optionalPermissions,
366 PermissionSet refusedPermissions)
368 return DefineDynamicAssembly (name, access, null, evidence, requiredPermissions, optionalPermissions,
369 refusedPermissions, false);
372 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
373 PermissionSet requiredPermissions,
374 PermissionSet optionalPermissions,
375 PermissionSet refusedPermissions)
377 return DefineDynamicAssembly (name, access, dir, null, requiredPermissions, optionalPermissions,
378 refusedPermissions, false);
381 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
383 PermissionSet requiredPermissions,
384 PermissionSet optionalPermissions,
385 PermissionSet refusedPermissions)
387 return DefineDynamicAssembly (name, access, dir, evidence, requiredPermissions, optionalPermissions,
388 refusedPermissions, false);
391 [MonoTODO ("FIXME: examine all other parameters")]
392 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
394 PermissionSet requiredPermissions,
395 PermissionSet optionalPermissions,
396 PermissionSet refusedPermissions, bool isSynchronized)
398 // FIXME: examine all other parameters
400 AssemblyBuilder ab = new AssemblyBuilder (name, dir, access, false);
401 ab.AddPermissionRequests (requiredPermissions, optionalPermissions, refusedPermissions);
405 internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
407 return new AssemblyBuilder (name, null, access, true);
410 public void DoCallBack (CrossAppDomainDelegate theDelegate)
412 if (theDelegate != null)
416 public int ExecuteAssembly (string assemblyFile)
418 return ExecuteAssembly (assemblyFile, null, null);
421 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity)
423 return ExecuteAssembly (assemblyFile, assemblySecurity, null);
426 [MethodImplAttribute (MethodImplOptions.InternalCall)]
427 public extern int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args);
430 public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
432 throw new NotImplementedException ();
435 [MethodImplAttribute (MethodImplOptions.InternalCall)]
436 public extern Assembly [] GetAssemblies ();
438 [MethodImplAttribute (MethodImplOptions.InternalCall)]
439 public extern object GetData (string name);
441 public new Type GetType()
443 return base.GetType ();
446 public override object InitializeLifetimeService ()
451 [MethodImplAttribute (MethodImplOptions.InternalCall)]
452 private extern Assembly LoadAssembly (string assemblyRef, Evidence securityEvidence);
454 public Assembly Load (AssemblyName assemblyRef)
456 return Load (assemblyRef, null);
459 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
461 if (assemblyRef == null)
462 throw new ArgumentNullException ("assemblyRef");
464 if (assemblyRef.Name == null || assemblyRef.Name.Length == 0) {
465 if (assemblyRef.CodeBase != null)
466 return Assembly.LoadFrom (assemblyRef.CodeBase, assemblySecurity);
468 throw new ArgumentException (Locale.GetText ("assemblyRef.Name cannot be empty."), "assemblyRef");
471 return LoadAssembly (assemblyRef.FullName, assemblySecurity);
474 public Assembly Load (string assemblyString)
476 if (assemblyString == null)
477 throw new ArgumentNullException ("assemblyString");
479 return LoadAssembly (assemblyString, null);
482 public Assembly Load (string assemblyString, Evidence assemblySecurity)
484 if (assemblyString == null)
485 throw new ArgumentNullException ("assemblyString");
487 return LoadAssembly (assemblyString, assemblySecurity);
490 public Assembly Load (byte[] rawAssembly)
492 return Load (rawAssembly, null, null);
495 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
497 return Load (rawAssembly, rawSymbolStore, null);
500 [MethodImplAttribute (MethodImplOptions.InternalCall)]
501 private extern Assembly LoadAssemblyRaw (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence);
503 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
505 if (rawAssembly == null)
506 throw new ArgumentNullException ("rawAssembly");
508 return LoadAssemblyRaw (rawAssembly, rawSymbolStore, securityEvidence);
511 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
512 public void SetAppDomainPolicy (PolicyLevel domainPolicy)
514 if (domainPolicy == null)
515 throw new ArgumentNullException ("domainPolicy");
516 if (_granted != null) {
517 throw new PolicyException (Locale.GetText (
518 "An AppDomain policy is already specified."));
520 if (IsFinalizingForUnload ())
521 throw new AppDomainUnloadedException ();
523 _granted = SecurityManager.ResolvePolicy (_evidence);
526 public void SetCachePath (string path)
528 SetupInformationNoCopy.CachePath = path;
531 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
532 public void SetPrincipalPolicy (PrincipalPolicy policy)
534 if (IsFinalizingForUnload ())
535 throw new AppDomainUnloadedException ();
537 _principalPolicy = policy;
541 public void SetShadowCopyFiles()
543 SetupInformationNoCopy.ShadowCopyFiles = "true";
546 public void SetShadowCopyPath (string path)
548 SetupInformationNoCopy.ShadowCopyDirectories = path;
551 [SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
552 public void SetThreadPrincipal (IPrincipal principal)
554 if (principal == null)
555 throw new ArgumentNullException ("principal");
556 if (_principal != null)
557 throw new PolicyException (Locale.GetText ("principal already present."));
558 if (IsFinalizingForUnload ())
559 throw new AppDomainUnloadedException ();
561 _principal = principal;
564 [MethodImplAttribute (MethodImplOptions.InternalCall)]
565 private static extern AppDomain InternalSetDomainByID (int domain_id);
567 // Changes the active domain and returns the old domain
568 [MethodImplAttribute (MethodImplOptions.InternalCall)]
569 private static extern AppDomain InternalSetDomain (AppDomain context);
571 // Notifies the runtime that this thread references 'domain'.
572 [MethodImplAttribute (MethodImplOptions.InternalCall)]
573 internal static extern void InternalPushDomainRef (AppDomain domain);
575 [MethodImplAttribute (MethodImplOptions.InternalCall)]
576 internal static extern void InternalPushDomainRefByID (int domain_id);
578 // Undoes the effect of the last PushDomainRef call
579 [MethodImplAttribute (MethodImplOptions.InternalCall)]
580 internal static extern void InternalPopDomainRef ();
582 // Changes the active context and returns the old context
583 [MethodImplAttribute (MethodImplOptions.InternalCall)]
584 internal static extern Context InternalSetContext (Context context);
586 // Returns the current context
587 [MethodImplAttribute (MethodImplOptions.InternalCall)]
588 internal static extern Context InternalGetContext ();
590 // Returns the current context
591 [MethodImplAttribute (MethodImplOptions.InternalCall)]
592 internal static extern Context InternalGetDefaultContext ();
594 [MethodImplAttribute (MethodImplOptions.InternalCall)]
595 internal static extern string InternalGetProcessGuid (string newguid);
597 // This method is handled specially by the runtime
598 // It is the only managed method which is allowed to set the current
600 internal static object InvokeInDomain (AppDomain domain, MethodInfo method, object obj, object [] args)
602 AppDomain current = CurrentDomain;
606 InternalPushDomainRef (domain);
608 InternalSetDomain (domain);
609 return ((MonoMethod) method).InternalInvoke (obj, args);
612 InternalSetDomain (current);
614 InternalPopDomainRef ();
618 internal static object InvokeInDomainByID (int domain_id, MethodInfo method, object obj, object [] args)
620 AppDomain current = CurrentDomain;
624 InternalPushDomainRefByID (domain_id);
626 InternalSetDomainByID (domain_id);
627 return ((MonoMethod) method).InternalInvoke (obj, args);
630 InternalSetDomain (current);
632 InternalPopDomainRef ();
636 internal static String GetProcessGuid ()
638 if (_process_guid == null) {
639 _process_guid = InternalGetProcessGuid (Guid.NewGuid().ToString ());
641 return _process_guid;
644 public static AppDomain CreateDomain (string friendlyName)
646 return CreateDomain (friendlyName, null, null);
649 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
651 return CreateDomain (friendlyName, securityInfo, null);
654 [MethodImplAttribute (MethodImplOptions.InternalCall)]
655 private static extern AppDomain createDomain (string friendlyName, AppDomainSetup info);
657 [MonoTODO ("allow setup in the other domain")]
658 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, AppDomainSetup info)
660 if (friendlyName == null)
661 throw new System.ArgumentNullException ("friendlyName");
664 // if null, get default domain's SetupInformation
665 AppDomain def = AppDomain.DefaultDomain;
667 info = new AppDomainSetup (); // we're default!
669 info = def.SetupInformation;
672 info = new AppDomainSetup (info); // copy
674 // todo: allow setup in the other domain
676 AppDomain ad = (AppDomain) RemotingServices.GetDomainProxy (createDomain (friendlyName, info));
677 if (securityInfo == null) {
678 // get default domain's Evidence (unless we're are the default!)
679 AppDomain def = AppDomain.DefaultDomain;
681 ad._evidence = null; // we'll get them later (GetEntryAssembly)
683 ad._evidence = def.Evidence; // new (shallow) copy
686 ad._evidence = new Evidence (securityInfo); // copy
691 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,string appBasePath,
692 string appRelativeSearchPath, bool shadowCopyFiles)
694 AppDomainSetup info = new AppDomainSetup ();
696 info.ApplicationBase = appBasePath;
697 info.PrivateBinPath = appRelativeSearchPath;
700 info.ShadowCopyFiles = "true";
702 info.ShadowCopyFiles = "false";
704 return CreateDomain (friendlyName, securityInfo, info);
707 [MethodImplAttribute (MethodImplOptions.InternalCall)]
708 private static extern bool InternalIsFinalizingForUnload (int domain_id);
710 public bool IsFinalizingForUnload()
712 return InternalIsFinalizingForUnload (getDomainID ());
715 [MethodImplAttribute (MethodImplOptions.InternalCall)]
716 static extern void InternalUnload (int domain_id);
718 // We do this because if the domain is a transparant proxy this
719 // will still return the correct domain id.
720 private int getDomainID ()
722 return Thread.GetDomainID ();
725 public static void Unload (AppDomain domain)
728 throw new ArgumentNullException ("domain");
730 InternalUnload (domain.getDomainID());
733 [MethodImplAttribute (MethodImplOptions.InternalCall)]
734 public extern void SetData (string name, object data);
736 public void SetDynamicBase (string path)
738 SetupInformationNoCopy.DynamicBase = path;
744 public static int GetCurrentThreadId ()
746 return Thread.CurrentThreadId;
749 public override string ToString ()
751 return getFriendlyName ();
754 // The following methods are called from the runtime. Don't change signatures.
755 private void DoAssemblyLoad (Assembly assembly)
757 if (AssemblyLoad == null)
760 AssemblyLoad (this, new AssemblyLoadEventArgs (assembly));
763 private Assembly DoAssemblyResolve (string name)
765 if (AssemblyResolve == null)
768 /* Prevent infinite recursion */
769 Hashtable ht = assembly_resolve_in_progress;
771 ht = new Hashtable ();
772 assembly_resolve_in_progress = ht;
775 if (ht.Contains (name))
781 foreach (Delegate eh in AssemblyResolve.GetInvocationList ()) {
782 ResolveEventHandler handler = (ResolveEventHandler) eh;
783 Assembly assembly = handler (this, new ResolveEventArgs (name));
784 if (assembly != null)
794 internal Assembly DoTypeResolve (Object name_or_tb)
796 if (TypeResolve == null)
801 if (name_or_tb is TypeBuilder)
802 name = ((TypeBuilder) name_or_tb).FullName;
804 name = (string) name_or_tb;
806 /* Prevent infinite recursion */
807 Hashtable ht = type_resolve_in_progress;
809 ht = new Hashtable ();
810 type_resolve_in_progress = ht;
813 if (ht.Contains (name))
819 foreach (Delegate d in TypeResolve.GetInvocationList ()) {
820 ResolveEventHandler eh = (ResolveEventHandler) d;
821 Assembly assembly = eh (this, new ResolveEventArgs (name));
822 if (assembly != null)
832 private void DoDomainUnload ()
834 if (DomainUnload != null)
835 DomainUnload(this, null);
838 internal byte[] GetMarshalledDomainObjRef ()
840 ObjRef oref = RemotingServices.Marshal (AppDomain.CurrentDomain, null, typeof (AppDomain));
841 return CADSerializer.SerializeObject (oref).GetBuffer();
844 internal void ProcessMessageInDomain (byte[] arrRequest, CADMethodCallMessage cadMsg,
845 out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
849 if (null != arrRequest)
850 reqDomMsg = CADSerializer.DeserializeMessage (new MemoryStream(arrRequest), null);
852 reqDomMsg = new MethodCall (cadMsg);
854 IMessage retDomMsg = ChannelServices.SyncDispatchMessage (reqDomMsg);
856 cadMrm = CADMethodReturnMessage.Create (retDomMsg);
857 if (null == cadMrm) {
858 arrResponse = CADSerializer.SerializeMessage (retDomMsg).GetBuffer();
864 // End of methods called from the runtime
866 public event AssemblyLoadEventHandler AssemblyLoad;
868 public event ResolveEventHandler AssemblyResolve;
870 public event EventHandler DomainUnload;
872 public event EventHandler ProcessExit;
874 public event ResolveEventHandler ResourceResolve;
876 public event ResolveEventHandler TypeResolve;
878 public event UnhandledExceptionEventHandler UnhandledException;
881 private ActivationContext _activation;
882 private AppDomainManager _domain_manager;
886 public ActivationContext ActivationContext {
887 get { return _activation; }
891 public AppDomainManager DomainManager {
892 get { return _domain_manager; }
896 get { return getDomainID (); }
901 [MonoTODO ("what's the policy affecting names ?")]
903 public string ApplyPolicy (string assemblyName)
905 if (assemblyName == null)
906 throw new ArgumentNullException ("assemblyName");
907 if (assemblyName.Length == 0) // String.Empty
908 throw new ArgumentException ("assemblyName");
915 // LAMESPEC: Only the fist argument (full path to application) is documented
916 public static bool Activate (string[] args)
919 throw new ArgumentNullException ("args");
920 // TODO - what class implements IApplicationDescription ?
921 return ActivateNewProcess (null);
925 public static bool ActivateNewProcess (IApplicationDescription appDescription)
927 if (appDescription == null)
928 throw new ArgumentNullException ("appDescription");
932 [MonoTODO ("add support for new delegate")]
933 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo, string appBasePath,
934 string appRelativeSearchPath, bool shadowCopy, AppDomainInitializer adInit, string[] adInitArgs)
936 return CreateDomain (friendlyName, securityInfo, appBasePath, appRelativeSearchPath, shadowCopy);
939 [MonoTODO ("resolve assemblyName to location")]
940 public int ExecuteAssemblyByName (string assemblyName)
942 return ExecuteAssemblyByName (assemblyName, null, null);
945 [MonoTODO ("resolve assemblyName to location")]
946 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity)
948 return ExecuteAssemblyByName (assemblyName, assemblySecurity, null);
951 [MonoTODO ("resolve assemblyName to location")]
952 public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity, string[] args)
954 if (assemblyName == null)
955 throw new ArgumentNullException ("assemblyName");
957 AssemblyName an = new AssemblyName (assemblyName);
958 return ExecuteAssemblyByName (an, assemblySecurity, args);
961 [MonoTODO ("assemblyName may not have a codebase")]
962 public int ExecuteAssemblyByName (AssemblyName assemblyName, Evidence assemblySecurity, string[] args)
964 if (assemblyName == null)
965 throw new ArgumentNullException ("assemblyName");
967 return ExecuteAssembly (assemblyName.CodeBase, assemblySecurity, args);
970 public bool IsDefaultAppDomain ()
975 [MonoTODO ("see Assembly.ReflectionOnlyLoad")]
976 public Assembly[] ReflectionOnlyGetAssemblies ()
978 return new Assembly [0];