Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / class / corlib / System / AppDomain.cs
index eb2d545df37a8a34f0dac42eb6f4e20e8d8e9478..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;
@@ -61,6 +64,7 @@ namespace System {
        [ComDefaultInterface (typeof (_AppDomain))]
 #endif
        [ClassInterface(ClassInterfaceType.None)]
+       [StructLayout (LayoutKind.Sequential)]
 #if MOONLIGHT
        public sealed class AppDomain : _AppDomain {
 #elif NET_2_1
@@ -127,10 +131,12 @@ namespace System {
                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;
                        }
                }
@@ -138,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;
                        }
                }
@@ -153,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;
                        }
                }
@@ -306,6 +316,7 @@ namespace System {
                {
                        return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm);
                }
+#endif
 #endif
 
                public ObjectHandle CreateInstance (string assemblyName, string typeName)
@@ -459,8 +470,7 @@ 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);
@@ -598,6 +608,7 @@ namespace System {
                {
                        return new AssemblyBuilder (name, null, access, true);
                }
+#endif
 
                //
                // AppDomain.DoCallBack works because AppDomain is a MarshalByRefObject
@@ -1289,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 */
@@ -1320,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)
                {