Inheritance: System.MarshalByRefObject, IMessageSink
Exemplo n.º 1
0
            [System.Security.SecurityCritical]  // auto-generated
            internal ServerIdentity StartupWellKnownObject(
                String asmName, String svrTypeName, String URI, 
                WellKnownObjectMode mode,
                bool fReplace)
            {
                lock (s_wkoStartLock)
                {                
                    MarshalByRefObject obj = null;
                    ServerIdentity srvID = null;

                    // attempt to load the type                
                    Type serverType = LoadType(svrTypeName, asmName);
                
                    // make sure the well known object derives from MarshalByRefObject
                    if(!serverType.IsMarshalByRef)
                    {   
                        throw new RemotingException(
                            Environment.GetResourceString("Remoting_WellKnown_MustBeMBR",
                            svrTypeName));                         
                    }

                    // make sure that no one beat us to creating
                    // the well known object
                    srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                    if ((srvID != null) && srvID.IsRemoteDisconnected())
                    {
                        IdentityHolder.RemoveIdentity(URI);
                        srvID = null;
                    }
                                        
                    if (srvID == null)
                    {                    
                        //WellKnown type instances need to be created under full trust
                        //since the permission set might have been restricted by the channel 
                        //pipeline.           
                        //This assert is protected by Infrastructure link demands.
                        s_fullTrust.Assert();                
                        try {                    
                            obj = (MarshalByRefObject)Activator.CreateInstance(serverType, true);
                                                 
                            if (RemotingServices.IsClientProxy(obj))
                            {
                                // The wellknown type is remoted so we must wrap the proxy
                                // with a local object.

                                // The redirection proxy masquerades as an object of the appropriate
                                // type, and forwards incoming messages to the actual proxy.
                                RedirectionProxy redirectedProxy = new RedirectionProxy(obj, serverType);
                                redirectedProxy.ObjectMode = mode;

                                // DevDiv 720951 and 911924:
                                // 'isInitializing' is propagated into the new ServerIdentity so that other concurrent
                                // operations that find it in URITable do not use it prematurely.
                                RemotingServices.MarshalInternal(redirectedProxy, URI, serverType, updateChannelData: true, isInitializing: true);

                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                                Contract.Assert(null != srvID, "null != srvID");

                                // The redirection proxy handles SingleCall versus Singleton,
                                // so we always set its mode to Singleton.
                                srvID.SetSingletonObjectMode();
                            }
                            else
                            if (serverType.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                            {
                                // Singleton COM objects are wrapped, so that they will be
                                //   recreated when an RPC server not available is thrown
                                //   if dllhost.exe is killed.
                                ComRedirectionProxy comRedirectedProxy = new ComRedirectionProxy(obj, serverType);

                                // DevDiv 720951 and 911924: isInitializing = true
                                RemotingServices.MarshalInternal(comRedirectedProxy, URI, serverType, updateChannelData: true, isInitializing: true);

                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                                Contract.Assert(null != srvID, "null != srvID");

                                // Only singleton COM objects are redirected this way.
                                srvID.SetSingletonObjectMode();
                            }
                            else
                            {
                                // make sure the object didn't Marshal itself.
                                String tempUri = RemotingServices.GetObjectUri(obj);
                                if (tempUri != null)
                                {
                                    throw new RemotingException(
                                        String.Format(
                                            CultureInfo.CurrentCulture, Environment.GetResourceString(
                                                "Remoting_WellKnown_CtorCantMarshal"),
                                            URI));
                                }

                                // DevDiv 720951 and 911924: isInitializing = true
                                RemotingServices.MarshalInternal(obj, URI, serverType, updateChannelData: true, isInitializing: true);

                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                                Contract.Assert(null != srvID, "null != srvID");

                                if (mode == WellKnownObjectMode.SingleCall)
                                {
                                    // We need to set a special flag in the serverId
                                    // so that every dispatch to this type creates 
                                    // a new instance of the server object
                                    srvID.SetSingleCallObjectMode();
                                }
                                else
                                {
                                    srvID.SetSingletonObjectMode();
                                }
                            }

                        }
                        catch
                        {
                            // DevDiv 720951 and 911924:
                            // An exception thrown in the scope of this attempt to create a
                            // new ServerIdentity may leave a ServerIdentity instance in the
                            // URITable that has not been properly initialized.  This condition
                            // has been true for all versions of the framework but was first
                            // recognized in making this fix in 4.5.3.  Ideally, a damaged
                            // ServerIdentity should be removed from URITable.  But due to risk
                            // and lack of customer reports of a problem, we chose not to fix it.
                            throw;
                        }
                        finally {

                            // DevDiv 720951 and 911924:
                            // This flag is cleared only after the new ServerIdentity is completely
                            // initialized and ready for use.  It is done here in the 'finally' to
                            // ensure all exit paths reset the flag, including exceptions.
                            if (srvID != null)
                            {
                                srvID.IsInitializing = false;
                            }

                            SecurityPermission.RevertAssert();
                        }
                    }
                    
                    Contract.Assert(null != srvID, "null != srvID");
                    return srvID;
                }
            } // StartupWellKnownObject
 internal ServerIdentity StartupWellKnownObject(string asmName, string svrTypeName, string URI, WellKnownObjectMode mode, bool fReplace)
 {
     lock (s_wkoStartLock)
     {
         MarshalByRefObject obj2 = null;
         ServerIdentity identity = null;
         Type type = LoadType(svrTypeName, asmName);
         if (!type.IsMarshalByRef)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_WellKnown_MustBeMBR", new object[] { svrTypeName }));
         }
         identity = (ServerIdentity) IdentityHolder.ResolveIdentity(URI);
         if ((identity != null) && identity.IsRemoteDisconnected())
         {
             IdentityHolder.RemoveIdentity(URI);
             identity = null;
         }
         if (identity == null)
         {
             s_fullTrust.Assert();
             try
             {
                 obj2 = (MarshalByRefObject) Activator.CreateInstance(type, true);
                 if (RemotingServices.IsClientProxy(obj2))
                 {
                     RedirectionProxy proxy = new RedirectionProxy(obj2, type) {
                         ObjectMode = mode
                     };
                     RemotingServices.MarshalInternal(proxy, URI, type);
                     identity = (ServerIdentity) IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else if (type.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                 {
                     ComRedirectionProxy proxy2 = new ComRedirectionProxy(obj2, type);
                     RemotingServices.MarshalInternal(proxy2, URI, type);
                     identity = (ServerIdentity) IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else
                 {
                     if (RemotingServices.GetObjectUri(obj2) != null)
                     {
                         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { URI }));
                     }
                     RemotingServices.MarshalInternal(obj2, URI, type);
                     identity = (ServerIdentity) IdentityHolder.ResolveIdentity(URI);
                     if (mode == WellKnownObjectMode.SingleCall)
                     {
                         identity.SetSingleCallObjectMode();
                     }
                     else
                     {
                         identity.SetSingletonObjectMode();
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
         }
         return identity;
     }
 }
Exemplo n.º 3
0
            [System.Security.SecurityCritical]  // auto-generated
            internal ServerIdentity StartupWellKnownObject( 
                String asmName, String svrTypeName, String URI, 
                WellKnownObjectMode mode,
                bool fReplace) 
            {
                lock (s_wkoStartLock)
                {
                    MarshalByRefObject obj = null; 
                    ServerIdentity srvID = null;
 
                    // attempt to load the type 
                    Type serverType = LoadType(svrTypeName, asmName);
 
                    // make sure the well known object derives from MarshalByRefObject
                    if(!serverType.IsMarshalByRef)
                    {
                        throw new RemotingException( 
                            Environment.GetResourceString("Remoting_WellKnown_MustBeMBR",
                            svrTypeName)); 
                    } 

                    // make sure that no one beat us to creating 
                    // the well known object
                    srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                    if ((srvID != null) && srvID.IsRemoteDisconnected())
                    { 
                        IdentityHolder.RemoveIdentity(URI);
                        srvID = null; 
                    } 

                    if (srvID == null) 
                    {
                        //WellKnown type instances need to be created under full trust
                        //since the permission set might have been restricted by the channel
                        //pipeline. 
                        //This assert is protected by Infrastructure link demands.
                        s_fullTrust.Assert(); 
                        try { 
                            obj = (MarshalByRefObject)Activator.CreateInstance(serverType, true);
 
                            if (RemotingServices.IsClientProxy(obj))
                            {
                                // The wellknown type is remoted so we must wrap the proxy
                                // with a local object. 

                                // The redirection proxy masquerades as an object of the appropriate 
                                // type, and forwards incoming messages to the actual proxy. 
                                RedirectionProxy redirectedProxy = new RedirectionProxy(obj, serverType);
                                redirectedProxy.ObjectMode = mode; 
                                RemotingServices.MarshalInternal(redirectedProxy, URI, serverType);

                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                                Contract.Assert(null != srvID, "null != srvID"); 

                                // The redirection proxy handles SingleCall versus Singleton, 
                                // so we always set its mode to Singleton. 
                                srvID.SetSingletonObjectMode();
                            } 
                            else
                            if (serverType.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                            {
                                // Singleton COM objects are wrapped, so that they will be 
                                //   recreated when an RPC server not available is thrown
                                //   if dllhost.exe is killed. 
                                ComRedirectionProxy comRedirectedProxy = new ComRedirectionProxy(obj, serverType); 
                                RemotingServices.MarshalInternal(comRedirectedProxy, URI, serverType);
 
                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                                Contract.Assert(null != srvID, "null != srvID");

                                // Only singleton COM objects are redirected this way. 
                                srvID.SetSingletonObjectMode();
                            } 
                            else 
                            {
                                // make sure the object didn't Marshal itself. 
                                String tempUri = RemotingServices.GetObjectUri(obj);
                                if (tempUri != null)
                                {
                                    throw new RemotingException( 
                                        String.Format(
                                            CultureInfo.CurrentCulture, Environment.GetResourceString( 
                                                "Remoting_WellKnown_CtorCantMarshal"), 
                                            URI));
                                } 

                                RemotingServices.MarshalInternal(obj, URI, serverType);

                                srvID = (ServerIdentity)IdentityHolder.ResolveIdentity(URI); 
                                Contract.Assert(null != srvID, "null != srvID");
 
                                if (mode == WellKnownObjectMode.SingleCall) 
                                {
                                    // We need to set a special flag in the serverId 
                                    // so that every dispatch to this type creates
                                    // a new instance of the server object
                                    srvID.SetSingleCallObjectMode();
                                } 
                                else
                                { 
                                    srvID.SetSingletonObjectMode(); 
                                }
                            } 
                        }
                        catch
                        {
                            throw; 
                        }
                        finally { 
                            SecurityPermission.RevertAssert(); 
                        }
                    } 

                    Contract.Assert(null != srvID, "null != srvID");
                    return srvID;
                } 
            } // StartupWellKnownObject
 internal ServerIdentity StartupWellKnownObject(string asmName, string svrTypeName, string URI, WellKnownObjectMode mode, bool fReplace)
 {
     lock (s_wkoStartLock)
     {
         MarshalByRefObject obj2     = null;
         ServerIdentity     identity = null;
         Type type = LoadType(svrTypeName, asmName);
         if (!type.IsMarshalByRef)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_WellKnown_MustBeMBR", new object[] { svrTypeName }));
         }
         identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
         if ((identity != null) && identity.IsRemoteDisconnected())
         {
             IdentityHolder.RemoveIdentity(URI);
             identity = null;
         }
         if (identity == null)
         {
             s_fullTrust.Assert();
             try
             {
                 obj2 = (MarshalByRefObject)Activator.CreateInstance(type, true);
                 if (RemotingServices.IsClientProxy(obj2))
                 {
                     RedirectionProxy proxy = new RedirectionProxy(obj2, type)
                     {
                         ObjectMode = mode
                     };
                     RemotingServices.MarshalInternal(proxy, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else if (type.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                 {
                     ComRedirectionProxy proxy2 = new ComRedirectionProxy(obj2, type);
                     RemotingServices.MarshalInternal(proxy2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else
                 {
                     if (RemotingServices.GetObjectUri(obj2) != null)
                     {
                         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { URI }));
                     }
                     RemotingServices.MarshalInternal(obj2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     if (mode == WellKnownObjectMode.SingleCall)
                     {
                         identity.SetSingleCallObjectMode();
                     }
                     else
                     {
                         identity.SetSingletonObjectMode();
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
         }
         return(identity);
     }
 }