Merge pull request #1135 from kitsilanosoftware/rpm-spec-dead-entries
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Activation / ActivationServices.cs
index 0a0022f6017008aa1cd53fcd4f8a9788a3334ef1..3756f1df9b0f3820050a438e0c0a8cc625328698 100644 (file)
@@ -44,18 +44,28 @@ namespace System.Runtime.Remoting.Activation
 {
        internal class ActivationServices
        {
-               static IActivator _constructionActivator = new ConstructionLevelActivator ();
+               static IActivator _constructionActivator;
+
+               static IActivator ConstructionActivator {
+                       get {
+                               if (_constructionActivator == null)
+                                       _constructionActivator = new ConstructionLevelActivator ();
+
+                               return _constructionActivator;
+                       }
+               }
 
                public static IMessage Activate (RemotingProxy proxy, ConstructionCall ctorCall)
                {
                        IMessage response;
+                       ctorCall.SourceProxy = proxy;
 
                        if (Thread.CurrentContext.HasExitSinks && !ctorCall.IsContextOk)
                                response = Thread.CurrentContext.GetClientContextSinkChain ().SyncProcessMessage (ctorCall);
                        else
                                response = RemoteActivate (ctorCall);
 
-                       if (response is IConstructionReturnMessage && ((IConstructionReturnMessage)response).Exception == null)
+                       if (response is IConstructionReturnMessage && ((IConstructionReturnMessage)response).Exception == null && proxy.ObjectIdentity == null)
                        {
                                Identity identity = RemotingServices.GetMessageTargetIdentity (ctorCall);
                                proxy.AttachIdentity (identity);
@@ -66,14 +76,14 @@ namespace System.Runtime.Remoting.Activation
 
                public static IMessage RemoteActivate (IConstructionCallMessage ctorCall)
                {
-                       try \r
+                       try 
                        {
                                return ctorCall.Activator.Activate (ctorCall);
                        }
-                       catch (Exception ex) \r
+                       catch (Exception ex) 
                        {
                                return new ReturnMessage (ex, ctorCall);
-                       }               \r
+                       }               
                }
 
                public static object CreateProxyFromAttributes (Type type, object[] activationAttributes)
@@ -105,7 +115,7 @@ namespace System.Runtime.Remoting.Activation
                        if (!type.IsContextful) 
                        {
                                // Must be a remote activated object
-                               ctorCall.Activator = new AppDomainLevelActivator (activationUrl, _constructionActivator);
+                               ctorCall.Activator = new AppDomainLevelActivator (activationUrl, ConstructionActivator);
                                ctorCall.IsContextOk = false;   // It'll be activated in a remote context
                                return ctorCall;
                        }
@@ -113,7 +123,7 @@ namespace System.Runtime.Remoting.Activation
                        // It is a CBO. Need collect context properties and
                        // check if a new context is needed.
 
-                       IActivator activatorChain = _constructionActivator;
+                       IActivator activatorChain = ConstructionActivator;
                        activatorChain = new ContextLevelActivator (activatorChain);
 
                        ArrayList attributes = new ArrayList ();
@@ -167,12 +177,21 @@ namespace System.Runtime.Remoting.Activation
                public static IMessage CreateInstanceFromMessage (IConstructionCallMessage ctorCall)
                {
                        object obj = AllocateUninitializedClassInstance (ctorCall.ActivationType);
-                       ctorCall.MethodBase.Invoke (obj, ctorCall.Args);
 
                        ServerIdentity identity = (ServerIdentity) RemotingServices.GetMessageTargetIdentity (ctorCall);
-
                        identity.AttachServerObject ((MarshalByRefObject) obj, Threading.Thread.CurrentContext);
 
+                       ConstructionCall call = ctorCall as ConstructionCall;
+
+                       if (ctorCall.ActivationType.IsContextful && call != null && call.SourceProxy != null)
+                       {
+                               call.SourceProxy.AttachIdentity (identity);
+                               MarshalByRefObject target = (MarshalByRefObject) call.SourceProxy.GetTransparentProxy ();
+                               RemotingServices.InternalExecuteMessage (target, ctorCall);
+                       }
+                       else
+                               ctorCall.MethodBase.Invoke (obj, ctorCall.Args);
+
                        return new ConstructionResponse (obj, null, ctorCall);
                }
 
@@ -194,7 +213,11 @@ namespace System.Runtime.Remoting.Activation
 
                        if (type.IsContextful)
                                return RemotingServices.CreateClientProxyForContextBound (type, null);
-
+#if !NET_2_1
+                       if (type.IsCOMObject) {
+                               return RemotingServices.CreateClientProxyForComInterop (type);
+                       }
+#endif
                        return null;
                }