Add all missing sequential layout directives to corlib and system.
[mono.git] / mcs / class / corlib / System / AppDomain.cs
index b73252f49c0275e100d93650332bb3385c0bcdf6..1cb3be10c3b1f38d18927ba40542778ddb35b3a2 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
@@ -57,12 +58,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
@@ -125,10 +129,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;
                        }
                }
@@ -136,10 +142,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 +159,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;
                        }
                }
@@ -679,10 +689,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);
@@ -739,14 +751,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);
@@ -1316,19 +1328,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)
                {
@@ -1374,7 +1404,7 @@ 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; }
@@ -1536,7 +1566,7 @@ namespace System {
                }
 #endif
 
-#if NET_4_0 || MOONLIGHT
+#if NET_4_0 || MOONLIGHT || MOBILE
                List<string> compatibility_switch;
 
                public bool? IsCompatibilitySwitchSet (string value)