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);
}
}