Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / class / corlib / System / AppDomain.cs
index 259477b0a59c0e92cfc07024b8d4cc5e2abe0f70..7032f7054f55087f31adcfc2bd611a1c760c7a4c 100644 (file)
@@ -11,6 +11,7 @@
 //
 // (C) 2001, 2002 Ximian, Inc.  http://www.ximian.com
 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -36,7 +37,9 @@ using System.Collections;
 using System.Globalization;
 using System.IO;
 using System.Reflection;
+#if !FULL_AOT_RUNTIME
 using System.Reflection.Emit;
+#endif
 using System.Threading;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
@@ -57,12 +60,15 @@ using System.Text;
 namespace System {
 
        [ComVisible (true)]
-#if !NET_2_1
+#if !NET_2_1 || MOONLIGHT
        [ComDefaultInterface (typeof (_AppDomain))]
 #endif
        [ClassInterface(ClassInterfaceType.None)]
-#if NET_2_1
-       public sealed class AppDomain : MarshalByRefObject {
+       [StructLayout (LayoutKind.Sequential)]
+#if MOONLIGHT
+       public sealed class AppDomain : _AppDomain {
+#elif NET_2_1
+       public sealed class AppDomain : MarshalByRefObject, _AppDomain {
 #else
        public sealed class AppDomain : MarshalByRefObject, _AppDomain, IEvidenceFactory {
 #endif
@@ -81,7 +87,7 @@ namespace System {
 
                [ThreadStatic]
                static Hashtable assembly_resolve_in_progress_refonly;
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
                // CAS
                private Evidence _evidence;
                private PermissionSet _granted;
@@ -121,14 +127,16 @@ namespace System {
                        get { throw new NotImplementedException (); }
                }
 #endif
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
                public string BaseDirectory {
                        get {
                                string path = SetupInformationNoCopy.ApplicationBase;
+#if !NET_2_1
                                if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
                                        // we cannot divulge local file informations
                                        new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
                                }
+#endif
                                return path;
                        }
                }
@@ -136,10 +144,12 @@ namespace System {
                public string RelativeSearchPath {
                        get {
                                string path = SetupInformationNoCopy.PrivateBinPath;
+#if !NET_2_1
                                if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
                                        // we cannot divulge local file informations
                                        new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
                                }
+#endif
                                return path;
                        }
                }
@@ -151,10 +161,12 @@ namespace System {
                                        return null;
 
                                string path = Path.Combine (setup.DynamicBase, setup.ApplicationName);
+#if !NET_2_1
                                if (SecurityManager.SecurityEnabled && (path != null) && (path.Length > 0)) {
                                        // we cannot divulge local file informations
                                        new FileIOPermission (FileIOPermissionAccess.PathDiscovery, path).Demand ();
                                }
+#endif
                                return path;
                        }
                }
@@ -174,7 +186,7 @@ namespace System {
                                return getFriendlyName ();
                        }
                }
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
                public Evidence Evidence {
                        get {
                                // if the host (runtime) hasn't provided it's own evidence...
@@ -223,6 +235,13 @@ namespace System {
                        get { return _granted; }
                }
 #endif
+
+#if NET_4_0
+               public PermissionSet PermissionSet {
+                       get { return _granted ?? (_granted = new PermissionSet (PermissionState.Unrestricted)); }
+               }
+#endif
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private static extern AppDomain getCurDomain ();
                
@@ -248,7 +267,7 @@ namespace System {
                        }
                }
 
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
 
                [Obsolete ("AppDomain.AppendPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead.")]
                [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
@@ -297,6 +316,7 @@ namespace System {
                {
                        return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm);
                }
+#endif
 #endif
 
                public ObjectHandle CreateInstance (string assemblyName, string typeName)
@@ -315,6 +335,9 @@ namespace System {
                        return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
                                                    Binder binder, object[] args, CultureInfo culture, object[] activationAttributes,
                                                    Evidence securityAttributes)
@@ -338,6 +361,9 @@ namespace System {
                        return (oh != null) ? oh.Unwrap () : null;
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
                                                       BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
                                                       object[] activationAttributes, Evidence securityAttributes)
@@ -347,6 +373,47 @@ namespace System {
                        return (oh != null) ? oh.Unwrap () : null;
                }
 
+#if NET_4_0
+               public ObjectHandle CreateInstance (string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr,
+                                                   Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
+               {
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
+                               culture, activationAttributes, null);
+               }
+               public object CreateInstanceAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
+                                                      BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
+                                                      object[] activationAttributes)
+               {
+                       ObjectHandle oh = CreateInstance (assemblyName, typeName, ignoreCase, bindingAttr, binder, args,
+                               culture, activationAttributes);
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+
+               public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
+                                                       BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
+                                                       object[] activationAttributes)
+               {
+                       if (assemblyFile == null)
+                               throw new ArgumentNullException ("assemblyFile");
+
+                       return Activator.CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
+                                                            culture, activationAttributes, null);
+               }
+
+               public object CreateInstanceFromAndUnwrap (string assemblyFile, string typeName, bool ignoreCase,
+                                                          BindingFlags bindingAttr, Binder binder, object[] args,
+                                                          CultureInfo culture, object[] activationAttributes)
+               {
+                       ObjectHandle oh = CreateInstanceFrom (assemblyFile, typeName, ignoreCase, bindingAttr, binder, args,
+                               culture, activationAttributes);
+
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+#endif
+
                public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName)
                {
                        if (assemblyFile == null)
@@ -363,6 +430,9 @@ namespace System {
                        return Activator.CreateInstanceFrom (assemblyFile, typeName, activationAttributes);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase,
                                                        BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture,
                                                        object[] activationAttributes, Evidence securityAttributes)
@@ -386,6 +456,9 @@ namespace System {
                        return (oh != null) ? oh.Unwrap () : null;
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName, bool ignoreCase,
                                                           BindingFlags bindingAttr, Binder binder, object[] args,
                                                           CultureInfo culture, object[] activationAttributes,
@@ -397,13 +470,15 @@ namespace System {
                        return (oh != null) ? oh.Unwrap () : null;
                }
 
-#endif // !NET_2_1
-
+#if !FULL_AOT_RUNTIME
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
                {
                        return DefineDynamicAssembly (name, access, null, null, null, null, null, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence)
                {
                        return DefineDynamicAssembly (name, access, null, evidence, null, null, null, false);
@@ -414,12 +489,18 @@ namespace System {
                        return DefineDynamicAssembly (name, access, dir, null, null, null, null, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
                                                              Evidence evidence)
                {
                        return DefineDynamicAssembly (name, access, dir, evidence, null, null, null, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access,
                                                              PermissionSet requiredPermissions,
                                                              PermissionSet optionalPermissions,
@@ -429,6 +510,9 @@ namespace System {
                                refusedPermissions, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
                                                              PermissionSet requiredPermissions,
                                                              PermissionSet optionalPermissions,
@@ -438,6 +522,9 @@ namespace System {
                                refusedPermissions, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
                                                              PermissionSet requiredPermissions,
                                                              PermissionSet optionalPermissions,
@@ -447,6 +534,9 @@ namespace System {
                                refusedPermissions, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
                                                              Evidence evidence,
                                                              PermissionSet requiredPermissions,
@@ -457,6 +547,9 @@ namespace System {
                                refusedPermissions, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
                                                              Evidence evidence,
                                                              PermissionSet requiredPermissions,
@@ -475,6 +568,9 @@ namespace System {
                }
 
                // NET 3.5 method
+#if NET_4_0
+               [Obsolete ("Declarative security for assembly level is no longer enforced")]
+#endif
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir,
                                                              Evidence evidence,
                                                              PermissionSet requiredPermissions,
@@ -490,14 +586,29 @@ namespace System {
                }
 
                // NET 3.5 method
-               public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes) {
+               public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
+               {
                        return DefineDynamicAssembly (name, access, null, null, null, null, null, false, assemblyAttributes);
                }
 
+#if NET_4_0
+               public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, string dir, bool isSynchronized, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
+               {
+                       return DefineDynamicAssembly (name, access, dir, null, null, null, null, isSynchronized, assemblyAttributes);
+               }
+
+               [MonoLimitation ("The argument securityContextSource is ignored")]
+               public AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes, SecurityContextSource securityContextSource)
+               {
+                       return DefineDynamicAssembly (name, access, assemblyAttributes);
+               }
+#endif
+
                internal AssemblyBuilder DefineInternalDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
                {
                        return new AssemblyBuilder (name, null, access, true);
                }
+#endif
 
                //
                // AppDomain.DoCallBack works because AppDomain is a MarshalByRefObject
@@ -511,26 +622,50 @@ namespace System {
 
                public int ExecuteAssembly (string assemblyFile)
                {
-                       return ExecuteAssembly (assemblyFile, null, null);
+                       return ExecuteAssembly (assemblyFile, (Evidence)null, null);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity)
                {
                        return ExecuteAssembly (assemblyFile, assemblySecurity, null);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args)
                {
                        Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity);
                        return ExecuteAssemblyInternal (a, args);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssembly (string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
                {
                        Assembly a = Assembly.LoadFrom (assemblyFile, assemblySecurity, hashValue, hashAlgorithm);
                        return ExecuteAssemblyInternal (a, args);
                }
 
+
+#if NET_4_0
+               public int ExecuteAssembly (string assemblyFile, string[] args)
+               {
+                       Assembly a = Assembly.LoadFrom (assemblyFile, null);
+                       return ExecuteAssemblyInternal (a, args);
+               }
+
+               public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
+               {
+                       Assembly a = Assembly.LoadFrom (assemblyFile, null, hashValue, hashAlgorithm);
+                       return ExecuteAssemblyInternal (a, args);
+               }
+#endif
+
                int ExecuteAssemblyInternal (Assembly a, string[] args)
                {
                        if (a.EntryPoint == null)
@@ -557,10 +692,12 @@ namespace System {
                        return base.GetType ();
                }
 
+#if !MOONLIGHT
                public override object InitializeLifetimeService ()
                {
                        return null;
                }
+#endif
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern Assembly LoadAssembly (string assemblyRef, Evidence securityEvidence, bool refOnly);
@@ -581,6 +718,9 @@ namespace System {
                        return result;
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
                {
                        if (assemblyRef == null)
@@ -614,14 +754,14 @@ namespace System {
                        if (assemblyRef.Name != aname.Name)
                                throw new FileNotFoundException (null, assemblyRef.Name);
 
-                       if (assemblyRef.Version != new Version () && assemblyRef.Version != aname.Version)
+                       if (assemblyRef.Version != null && assemblyRef.Version != new Version (0, 0, 0, 0) && assemblyRef.Version != aname.Version)
                                throw new FileNotFoundException (null, assemblyRef.Name);
 
                        if (assemblyRef.CultureInfo != null && assemblyRef.CultureInfo.Equals (aname))
                                throw new FileNotFoundException (null, assemblyRef.Name);
 
                        byte [] pt = assemblyRef.GetPublicKeyToken ();
-                       if (pt != null) {
+                       if (pt != null && pt.Length != 0) {
                                byte [] loaded_pt = aname.GetPublicKeyToken ();
                                if (loaded_pt == null || (pt.Length != loaded_pt.Length))
                                        throw new FileNotFoundException (null, assemblyRef.Name);
@@ -637,6 +777,9 @@ namespace System {
                        return Load (assemblyString, null, false);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public Assembly Load (string assemblyString, Evidence assemblySecurity)
                {
                        return Load (assemblyString, assemblySecurity, false);
@@ -669,6 +812,9 @@ namespace System {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern Assembly LoadAssemblyRaw (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence, bool refonly);
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
                {
                        return Load (rawAssembly, rawSymbolStore, securityEvidence, false);
@@ -683,7 +829,10 @@ namespace System {
                        assembly.FromByteArray = true;
                        return assembly;
                }
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
+#if NET_4_0
+               [Obsolete ("AppDomain policy levels are obsolete")]
+#endif
                [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
                public void SetAppDomainPolicy (PolicyLevel domainPolicy)
                {
@@ -832,7 +981,7 @@ namespace System {
                        return _process_guid;
                }
 
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
 
                public static AppDomain CreateDomain (string friendlyName)
                {
@@ -1042,7 +1191,7 @@ namespace System {
 
                public override string ToString ()
                {
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
                        return getFriendlyName ();
 #else
                        StringBuilder sb = new StringBuilder ("Name:");
@@ -1151,9 +1300,11 @@ namespace System {
 
                        string name;
 
+#if !FULL_AOT_RUNTIME
                        if (name_or_tb is TypeBuilder)
                                name = ((TypeBuilder) name_or_tb).FullName;
                        else
+#endif
                                name = (string) name_or_tb;
 
                        /* Prevent infinite recursion */
@@ -1182,19 +1333,37 @@ namespace System {
                        }
                }
 
+               internal Assembly DoResourceResolve (string name, Assembly requesting) {
+                       if (ResourceResolve == null)
+                               return null;
+
+                       Delegate[] invocation_list = ResourceResolve.GetInvocationList ();
+
+                       foreach (Delegate eh in invocation_list) {
+                               ResolveEventHandler handler = (ResolveEventHandler) eh;
+#if NET_4_0
+                               Assembly assembly = handler (this, new ResolveEventArgs (name, requesting));
+#else
+                               Assembly assembly = handler (this, new ResolveEventArgs (name));
+#endif
+                               if (assembly != null)
+                                       return assembly;
+                       }
+                       return null;
+               }
+
                private void DoDomainUnload ()
                {
                        if (DomainUnload != null)
                                DomainUnload(this, null);
                }
 
-#if !NET_2_1
                internal byte[] GetMarshalledDomainObjRef ()
                {
                        ObjRef oref = RemotingServices.Marshal (AppDomain.CurrentDomain, null, typeof (AppDomain));
                        return CADSerializer.SerializeObject (oref).GetBuffer();
                }
-#endif
+
                internal void ProcessMessageInDomain (byte[] arrRequest, CADMethodCallMessage cadMsg,
                                                      out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
                {
@@ -1240,11 +1409,16 @@ namespace System {
                [method: SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
                public event UnhandledExceptionEventHandler UnhandledException;
 
-#if NET_4_0 || BOOTSTRAP_NET_4_0
+#if NET_4_0
                [MonoTODO]
                public bool IsHomogenous {
                        get { return true; }
                }
+
+               [MonoTODO]
+               public bool IsFullyTrusted {
+                       get { return true; }
+               }
 #endif
 
         #pragma warning disable 649
@@ -1256,7 +1430,7 @@ namespace System {
                        get { return _domain_manager; }
                }
 
-#if (!NET_2_1 || MONOTOUCH)
+#if (!MOONLIGHT)
 
                public event ResolveEventHandler ReflectionOnlyAssemblyResolve;
 
@@ -1308,14 +1482,20 @@ namespace System {
 
                public int ExecuteAssemblyByName (string assemblyName)
                {
-                       return ExecuteAssemblyByName (assemblyName, null, null);
+                       return ExecuteAssemblyByName (assemblyName, (Evidence)null, null);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity)
                {
                        return ExecuteAssemblyByName (assemblyName, assemblySecurity, null);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssemblyByName (string assemblyName, Evidence assemblySecurity, params string[] args)
                {
                        Assembly a = Assembly.Load (assemblyName, assemblySecurity);
@@ -1323,6 +1503,9 @@ namespace System {
                        return ExecuteAssemblyInternal (a, args);
                }
 
+#if NET_4_0
+               [Obsolete ("Use an overload that does not take an Evidence parameter")]
+#endif
                public int ExecuteAssemblyByName (AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
                {
                        Assembly a = Assembly.Load (assemblyName, assemblySecurity);
@@ -1330,6 +1513,22 @@ namespace System {
                        return ExecuteAssemblyInternal (a, args);
                }
 
+#if NET_4_0
+               public int ExecuteAssemblyByName (string assemblyName, params string[] args)
+               {
+                       Assembly a = Assembly.Load (assemblyName, null);
+
+                       return ExecuteAssemblyInternal (a, args);
+               }
+
+               public int ExecuteAssemblyByName (AssemblyName assemblyName, params string[] args)
+               {
+                       Assembly a = Assembly.Load (assemblyName, null);
+
+                       return ExecuteAssemblyInternal (a, args);
+               }
+#endif
+
                public bool IsDefaultAppDomain ()
                {
                        return Object.ReferenceEquals (this, DefaultDomain);
@@ -1339,9 +1538,9 @@ namespace System {
                {
                        return GetAssemblies (true);
                }
-#endif
 
-#if NET_2_1 && !MONOTOUCH
+#else // MOONLIGHT
+
                public int ExecuteAssemblyByName (string assemblyName)
                {
                        // critical code in SL that we're not calling in ML
@@ -1371,5 +1570,51 @@ namespace System {
                        throw new NotImplementedException ();
                }
 #endif
+
+#if NET_4_0 || MOONLIGHT || MOBILE
+               List<string> compatibility_switch;
+
+               public bool? IsCompatibilitySwitchSet (string value)
+               {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+
+                       // default (at least for SL4) is to return false for unknown values (can't get a null out of it)
+                       return ((compatibility_switch != null) && compatibility_switch.Contains (value));
+               }
+
+               internal void SetCompatibilitySwitch (string value)
+               {
+                       if (compatibility_switch == null)
+                               compatibility_switch = new List<string> ();
+                       compatibility_switch.Add (value);
+               }
+
+               [MonoTODO ("Currently always returns false")]
+               public static bool MonitoringIsEnabled { 
+                       get { return false; }
+                       set { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public long MonitoringSurvivedMemorySize {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public static long MonitoringSurvivedProcessMemorySize {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public long MonitoringTotalAllocatedMemorySize {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public TimeSpan MonitoringTotalProcessorTime {
+                       get { throw new NotImplementedException (); }
+               }
+#endif
        }
 }