28 [__DynamicallyInvokable]
33 private const string FieldGetterName =
"FieldGetter";
35 private const string FieldSetterName =
"FieldSetter";
37 private const string IsInstanceOfTypeName =
"IsInstanceOfType";
39 private const string CanCastToXmlTypeName =
"CanCastToXmlType";
41 private const string InvokeMemberName =
"InvokeMember";
43 private static volatile MethodBase s_FieldGetterMB;
45 private static volatile MethodBase s_FieldSetterMB;
47 private static volatile MethodBase s_IsInstanceOfTypeMB;
49 private static volatile MethodBase s_CanCastToXmlTypeMB;
51 private static volatile MethodBase s_InvokeMemberMB;
53 private static volatile bool s_bRemoteActivationConfigured;
55 private static volatile bool s_bRegisteredWellKnownChannels;
57 private static bool s_bInProcessOfRegisteringWellKnownChannels;
59 private static readonly
object s_delayLoadChannelLock =
new object();
65 [SecuritySafeCritical]
66 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
73 [SecuritySafeCritical]
81 Identity identityObject = realProxy.IdentityObject;
82 ServerIdentity serverIdentity = identityObject as ServerIdentity;
83 if (serverIdentity ==
null || !(realProxy is RemotingProxy))
94 [__DynamicallyInvokable]
97 return IsClientProxy(tp);
100 internal static bool IsClientProxy(
object obj)
103 if (marshalByRefObject ==
null)
110 if (identity !=
null && !(identity is ServerIdentity))
118 internal static bool IsObjectOutOfProcess(
object tp)
125 Identity identityObject = realProxy.IdentityObject;
126 if (identityObject is ServerIdentity)
130 if (identityObject !=
null)
132 ObjRef objectRef = identityObject.ObjectRef;
133 if (objectRef !=
null && objectRef.IsFromThisProcess())
148 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
153 internal static extern object CreateTransparentProxy(
RealProxy rp, RuntimeType typeToProxy, IntPtr stub,
object stubData);
156 internal static object CreateTransparentProxy(
RealProxy rp, Type typeToProxy, IntPtr stub,
object stubData)
158 RuntimeType runtimeType = typeToProxy as RuntimeType;
159 if (runtimeType ==
null)
161 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Argument_WrongType"),
"typeToProxy"));
163 return CreateTransparentProxy(rp, runtimeType, stub, stubData);
168 internal static extern MarshalByRefObject AllocateUninitializedObject(RuntimeType objectType);
172 internal static extern void CallDefaultCtor(
object o);
175 internal static MarshalByRefObject AllocateUninitializedObject(Type objectType)
177 RuntimeType runtimeType = objectType as RuntimeType;
178 if (runtimeType ==
null)
180 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Argument_WrongType"),
"objectType"));
182 return AllocateUninitializedObject(runtimeType);
187 internal static extern MarshalByRefObject AllocateInitializedObject(RuntimeType objectType);
190 internal static MarshalByRefObject AllocateInitializedObject(Type objectType)
192 RuntimeType runtimeType = objectType as RuntimeType;
193 if (runtimeType ==
null)
195 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Argument_WrongType"),
"objectType"));
197 return AllocateInitializedObject(runtimeType);
201 internal static bool RegisterWellKnownChannels()
203 if (!s_bRegisteredWellKnownChannels)
205 bool lockTaken =
false;
211 if (!s_bRegisteredWellKnownChannels && !s_bInProcessOfRegisteringWellKnownChannels)
213 s_bInProcessOfRegisteringWellKnownChannels =
true;
214 CrossAppDomainChannel.RegisterChannel();
215 s_bRegisteredWellKnownChannels =
true;
230 internal static void InternalSetRemoteActivationConfigured()
232 if (!s_bRemoteActivationConfigured)
234 nSetRemoteActivationConfigured();
235 s_bRemoteActivationConfigured =
true;
241 private static extern void nSetRemoteActivationConfigured();
257 [SecuritySafeCritical]
260 return obj?.GetLifetimeService();
280 [SecuritySafeCritical]
284 Identity identity =
null;
285 Identity identity2 =
null;
287 identity2 = (identity as ServerIdentity);
288 if (identity !=
null && identity2 ==
null)
292 if (identity !=
null && identity.URI !=
null)
296 if (identity ==
null)
300 ServerIdentity serverIdentity =
new ServerIdentity(obj, context, uri);
301 identity = obj.__RaceSetServerIdentity(serverIdentity);
302 if (identity != serverIdentity)
309 identity.SetOrCreateURI(uri, bIdCtor:
true);
318 [SecuritySafeCritical]
322 return MarshalInternal(Obj,
null,
null);
332 [SecuritySafeCritical]
336 return MarshalInternal(Obj, URI,
null);
347 [SecuritySafeCritical]
351 return MarshalInternal(Obj, ObjURI, RequestedType);
357 return MarshalInternal(Obj, ObjURI, RequestedType, updateChannelData:
true);
361 internal static ObjRef MarshalInternal(
MarshalByRefObject Obj,
string ObjURI,
Type RequestedType,
bool updateChannelData)
363 return MarshalInternal(Obj, ObjURI, RequestedType, updateChannelData, isInitializing:
false);
367 internal static ObjRef MarshalInternal(
MarshalByRefObject Obj,
string ObjURI,
Type RequestedType,
bool updateChannelData,
bool isInitializing)
373 ObjRef objRef =
null;
374 Identity identity =
null;
375 identity = GetOrCreateIdentity(Obj, ObjURI, isInitializing);
376 if (RequestedType !=
null)
378 ServerIdentity serverIdentity = identity as ServerIdentity;
379 if (serverIdentity !=
null)
381 serverIdentity.ServerType = RequestedType;
382 serverIdentity.MarshaledAsSpecificType =
true;
385 objRef = identity.ObjectRef;
397 if (identity ==
null || objRef ==
null)
399 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidMarshalByRefObject"),
"Obj");
401 objRef = identity.RaceSetObjRef(objRef);
403 ServerIdentity serverIdentity2 = identity as ServerIdentity;
404 if (serverIdentity2 !=
null)
406 MarshalByRefObject obj =
null;
407 serverIdentity2.GetServerObjectChain(out obj);
408 Lease lease = identity.Lease;
415 lease.ActivateLease();
419 lease.RenewInternal(identity.Lease.InitialLeaseTime);
423 if (updateChannelData && objRef.ChannelInfo !=
null)
426 if (!(Obj is AppDomain))
428 objRef.ChannelInfo.ChannelData = currentChannelData;
432 int num = currentChannelData.Length;
433 object[] array =
new object[num];
434 Array.Copy(currentChannelData, array, num);
435 for (
int i = 0; i < num; i++)
437 if (!(array[i] is CrossAppDomainData))
442 objRef.ChannelInfo.ChannelData = array;
451 private static Identity GetOrCreateIdentity(MarshalByRefObject Obj,
string ObjURI,
bool isInitializing)
458 Identity identity =
null;
462 identity = realProxy.IdentityObject;
463 if (identity ==
null)
465 identity = IdentityHolder.FindOrCreateServerIdentity(Obj, ObjURI, num);
466 identity.RaceSetTransparentProxy(Obj);
468 ServerIdentity serverIdentity = identity as ServerIdentity;
469 if (serverIdentity !=
null)
471 identity = IdentityHolder.FindOrCreateServerIdentity(serverIdentity.TPOrObject, ObjURI, num);
472 if (ObjURI !=
null && ObjURI != Identity.RemoveAppNameOrAppGuidIfNecessary(identity.ObjURI))
474 throw new RemotingException(Environment.GetResourceString(
"Remoting_URIExists"));
477 else if (ObjURI !=
null && ObjURI != identity.ObjURI)
479 throw new RemotingException(Environment.GetResourceString(
"Remoting_URIToProxy"));
484 identity = IdentityHolder.FindOrCreateServerIdentity(Obj, ObjURI, num);
518 return InternalUnmarshal(objectRef,
null, fRefine:
false);
531 return InternalUnmarshal(objectRef,
null, fRefine);
543 return Unmarshal(classToProxy, url,
null);
554 public static object Connect(
Type classToProxy,
string url,
object data)
556 return Unmarshal(classToProxy, url, data);
582 if (identity !=
null)
584 if (!(identity is ServerIdentity))
586 throw new RemotingException(
Environment.GetResourceString(
"Remoting_CantDisconnectClientProxy"));
588 if (identity.IsInIDTable())
590 IdentityHolder.RemoveIdentity(identity.URI, bResetURI);
609 Identity identityObject = realProxy.IdentityObject;
610 if (identityObject !=
null)
612 result = identityObject.EnvoyChain;
631 Identity identityObject = realProxy.IdentityObject;
632 if (identityObject !=
null)
634 result = identityObject.ObjectRef;
640 internal static object Unmarshal(
Type classToProxy,
string url)
642 return Unmarshal(classToProxy, url,
null);
646 internal static object Unmarshal(
Type classToProxy,
string url,
object data)
648 if (
null == classToProxy)
658 throw new RemotingException(Environment.GetResourceString(
"Remoting_NotRemotableByReference"));
660 Identity identity = IdentityHolder.ResolveIdentity(url);
662 if (identity ==
null || identity.ChannelSink ==
null || identity.EnvoyChain ==
null)
667 text = CreateEnvoyAndChannelSinks(url, data, out chnlSink, out envoySink);
668 if (chnlSink ==
null)
670 throw new RemotingException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Remoting_Connect_CantCreateChannelSink"), url));
674 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidUrl"));
676 identity = IdentityHolder.FindOrCreateIdentity(text, url,
null);
677 SetEnvoyAndChannelSinks(identity, chnlSink, envoySink);
679 return GetOrCreateProxy(classToProxy, identity);
683 internal static object Wrap(ContextBoundObject obj)
685 return Wrap(obj,
null, fCreateSinks:
true);
689 internal static object Wrap(ContextBoundObject obj,
object proxy,
bool fCreateSinks)
693 Identity identity =
null;
697 if (realProxy.UnwrappedServerObject ==
null)
699 realProxy.AttachServerHelper(obj);
701 identity = MarshalByRefObject.GetIdentity(obj);
705 identity = IdentityHolder.FindOrCreateServerIdentity(obj,
null, 0);
707 proxy = GetOrCreateProxy(identity, proxy, fRefine:
true);
713 CreateEnvoyAndChannelSinks((MarshalByRefObject)proxy,
null, out chnlSink, out envoySink);
714 SetEnvoyAndChannelSinks(identity, chnlSink, envoySink);
717 if (realProxy2.UnwrappedServerObject ==
null)
719 realProxy2.AttachServerHelper(obj);
726 internal static string GetObjectUriFromFullUri(
string fullUri)
732 int num = fullUri.LastIndexOf(
'/');
737 return fullUri.Substring(num + 1);
742 internal static extern object Unwrap(ContextBoundObject obj);
746 internal static extern object AlwaysUnwrap(ContextBoundObject obj);
749 internal static object InternalUnmarshal(ObjRef objectRef,
object proxy,
bool fRefine)
752 Identity identity =
null;
754 if (!ObjRef.IsWellFormed(objectRef))
756 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Argument_BadObjRef"),
"Unmarshal"));
758 if (objectRef.IsWellKnown())
760 obj =
Unmarshal(typeof(MarshalByRefObject), objectRef.URI);
761 identity = IdentityHolder.ResolveIdentity(objectRef.URI);
762 if (identity.ObjectRef ==
null)
764 identity.RaceSetObjRef(objectRef);
768 identity = IdentityHolder.FindOrCreateIdentity(objectRef.URI,
null, objectRef);
770 ServerIdentity serverIdentity = identity as ServerIdentity;
771 if (serverIdentity !=
null)
774 if (!serverIdentity.IsContextBound)
778 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Remoting_BadInternalState_ProxySameAppDomain")));
780 obj = serverIdentity.TPOrObject;
786 CreateEnvoyAndChannelSinks(serverIdentity.TPOrObject,
null, out chnlSink, out envoySink);
787 SetEnvoyAndChannelSinks(identity, chnlSink, envoySink);
788 obj = GetOrCreateProxy(identity, proxy, fRefine:
true);
795 if (!objectRef.IsObjRefLite())
797 CreateEnvoyAndChannelSinks(
null, objectRef, out chnlSink2, out envoySink2);
801 CreateEnvoyAndChannelSinks(objectRef.URI,
null, out chnlSink2, out envoySink2);
803 SetEnvoyAndChannelSinks(identity, chnlSink2, envoySink2);
804 if (objectRef.HasProxyAttribute())
808 obj = GetOrCreateProxy(identity, proxy, fRefine);
815 private static object GetOrCreateProxy(Identity idObj,
object proxy,
bool fRefine)
819 ServerIdentity serverIdentity = idObj as ServerIdentity;
821 if (serverIdentity !=
null)
823 type = serverIdentity.ServerType;
827 IRemotingTypeInfo typeInfo = idObj.ObjectRef.TypeInfo;
829 if ((typeInfo is
TypeInfo && !fRefine) || typeInfo ==
null)
831 type = typeof(MarshalByRefObject);
835 string typeName = typeInfo.TypeName;
836 if (typeName !=
null)
838 string typeName2 =
null;
839 string assemName =
null;
840 TypeInfo.ParseTypeAndAssembly(typeName, out typeName2, out assemName);
842 if (assembly !=
null)
844 type = assembly.GetType(typeName2, throwOnError:
false, ignoreCase:
false);
850 throw new RemotingException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Remoting_BadType"), typeInfo.TypeName));
853 proxy = SetOrCreateProxy(idObj, type,
null);
857 proxy = SetOrCreateProxy(idObj,
null, proxy);
861 throw new RemotingException(Environment.GetResourceString(
"Remoting_UnexpectedNullTP"));
867 private static object GetOrCreateProxy(Type classToProxy, Identity idObj)
869 object obj = idObj.TPOrObject;
872 obj = SetOrCreateProxy(idObj, classToProxy,
null);
874 ServerIdentity serverIdentity = idObj as ServerIdentity;
875 if (serverIdentity !=
null)
877 Type serverType = serverIdentity.ServerType;
878 if (!classToProxy.IsAssignableFrom(serverType))
880 throw new InvalidCastException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"InvalidCast_FromTo"), serverType.FullName, classToProxy.FullName));
887 private static MarshalByRefObject SetOrCreateProxy(Identity idObj, Type classToProxy,
object proxy)
892 ServerIdentity serverIdentity = idObj as ServerIdentity;
893 if (idObj.ObjectRef !=
null)
895 ProxyAttribute proxyAttribute = ActivationServices.GetProxyAttribute(classToProxy);
896 realProxy = proxyAttribute.
CreateProxy(idObj.ObjectRef, classToProxy,
null,
null);
898 if (realProxy ==
null)
900 ProxyAttribute defaultProxyAttribute = ActivationServices.DefaultProxyAttribute;
901 realProxy = defaultProxyAttribute.
CreateProxy(idObj.ObjectRef, classToProxy,
null, serverIdentity?.ServerContext);
908 realProxy.IdentityObject = idObj;
910 proxy = idObj.RaceSetTransparentProxy(proxy);
911 return (MarshalByRefObject)proxy;
914 private static bool AreChannelDataElementsNull(
object[] channelData)
916 foreach (
object obj
in channelData)
927 internal static void CreateEnvoyAndChannelSinks(MarshalByRefObject tpOrObject, ObjRef objectRef, out
IMessageSink chnlSink, out
IMessageSink envoySink)
931 if (objectRef ==
null)
937 object[] channelData = objectRef.ChannelInfo.ChannelData;
938 if (channelData !=
null && !AreChannelDataElementsNull(channelData))
940 for (
int i = 0; i < channelData.Length; i++)
943 if (chnlSink !=
null)
948 if (chnlSink ==
null)
950 lock (s_delayLoadChannelLock)
952 for (
int j = 0; j < channelData.Length; j++)
955 if (chnlSink !=
null)
960 if (chnlSink ==
null)
962 object[] array = channelData;
963 foreach (
object data
in array)
965 chnlSink = RemotingConfigHandler.FindDelayLoadChannelForCreateMessageSink(
null, data, out
string _);
966 if (chnlSink !=
null)
975 if (objectRef.EnvoyInfo !=
null && objectRef.EnvoyInfo.EnvoySinks !=
null)
977 envoySink = objectRef.EnvoyInfo.EnvoySinks;
981 envoySink = EnvoyTerminatorSink.MessageSink;
986 internal static string CreateEnvoyAndChannelSinks(
string url,
object data, out
IMessageSink chnlSink, out
IMessageSink envoySink)
989 text = CreateChannelSink(url, data, out chnlSink);
990 envoySink = EnvoyTerminatorSink.MessageSink;
995 private static string CreateChannelSink(
string url,
object data, out
IMessageSink chnlSink)
997 string objectURI =
null;
998 chnlSink =
ChannelServices.CreateMessageSink(url, data, out objectURI);
999 if (chnlSink ==
null)
1001 lock (s_delayLoadChannelLock)
1003 chnlSink =
ChannelServices.CreateMessageSink(url, data, out objectURI);
1004 if (chnlSink !=
null)
1008 chnlSink = RemotingConfigHandler.FindDelayLoadChannelForCreateMessageSink(url, data, out objectURI);
1017 if (idObj.ChannelSink ==
null && chnlSink !=
null)
1019 idObj.RaceSetChannelSink(chnlSink);
1021 if (idObj.EnvoyChain ==
null)
1023 if (envoySink ==
null)
1025 throw new RemotingException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Remoting_BadInternalState_FailEnvoySink")));
1027 idObj.RaceSetEnvoyChain(envoySink);
1032 private static bool CheckCast(
RealProxy rp, RuntimeType castType)
1034 bool result =
false;
1035 if (castType == typeof(
object))
1039 if (!castType.IsInterface && !castType.IsMarshalByRef)
1045 IRemotingTypeInfo remotingTypeInfo = rp as IRemotingTypeInfo;
1046 if (remotingTypeInfo !=
null)
1052 Identity identityObject = rp.IdentityObject;
1053 if (identityObject !=
null)
1055 ObjRef objectRef = identityObject.ObjectRef;
1056 if (objectRef !=
null)
1058 remotingTypeInfo = objectRef.TypeInfo;
1059 if (remotingTypeInfo !=
null)
1071 internal static bool ProxyCheckCast(
RealProxy rp, RuntimeType castType)
1073 return CheckCast(rp, castType);
1078 internal static extern object CheckCast(
object objToExpand, RuntimeType type);
1081 internal static GCHandle CreateDelegateInvocation(WaitCallback waitDelegate,
object state)
1091 internal static void DisposeDelegateInvocation(
GCHandle delegateCallToken)
1093 delegateCallToken.
Free();
1097 internal static object CreateProxyForDomain(
int appDomainId, IntPtr defCtxID)
1100 ObjRef objectRef = CreateDataForDomain(appDomainId, defCtxID);
1105 internal static object CreateDataForDomainCallback(
object[] args)
1107 RegisterWellKnownChannels();
1108 ObjRef objRef = MarshalInternal(
Thread.
CurrentContext.AppDomain,
null,
null, updateChannelData:
false);
1109 ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity(
Thread.
CurrentContext.AppDomain);
1110 serverIdentity.SetHandle();
1111 objRef.SetServerIdentity(serverIdentity.GetHandle());
1112 objRef.SetDomainID(
AppDomain.CurrentDomain.GetId());
1117 internal static ObjRef CreateDataForDomain(
int appDomainId, IntPtr defCtxID)
1119 RegisterWellKnownChannels();
1120 InternalCrossContextDelegate ftnToCall = CreateDataForDomainCallback;
1121 return (ObjRef)
Thread.
CurrentThread.InternalCrossContextCallback(
null, defCtxID, appDomainId, ftnToCall,
null);
1131 return InternalGetMethodBaseFromMethodMessage(msg);
1141 Type type = InternalGetTypeFromQualifiedTypeName(msg.
TypeName);
1147 return GetMethodBase(msg, type, signature);
1159 return reflectionCachedData.IsOverloaded();
1168 if (signature ==
null)
1170 RuntimeType runtimeType = t as RuntimeType;
1172 if (1 != array.Length)
1180 RuntimeType runtimeType2 = t as RuntimeType;
1181 result = ((!(runtimeType2 ==
null)) ? runtimeType2.GetConstructor(signature) : t.
GetConstructor(signature));
1186 if (signature ==
null)
1188 RuntimeType runtimeType3 = t as RuntimeType;
1193 RuntimeType runtimeType4 = t as RuntimeType;
1201 internal static bool IsMethodAllowedRemotely(
MethodBase method)
1203 if (s_FieldGetterMB ==
null || s_FieldSetterMB ==
null || s_IsInstanceOfTypeMB ==
null || s_InvokeMemberMB ==
null || s_CanCastToXmlTypeMB ==
null)
1206 if (s_FieldGetterMB ==
null)
1210 if (s_FieldSetterMB ==
null)
1214 if (s_IsInstanceOfTypeMB ==
null)
1218 if (s_CanCastToXmlTypeMB ==
null)
1222 if (s_InvokeMemberMB ==
null)
1227 if (!(method == s_FieldGetterMB) && !(method == s_FieldSetterMB) && !(method == s_IsInstanceOfTypeMB) && !(method == s_InvokeMemberMB))
1229 return method == s_CanCastToXmlTypeMB;
1247 return reflectionCachedData.IsOneWayMethod();
1254 string value =
"Begin" + method.
Name;
1255 string value2 =
"End" + method.
Name;
1264 if (parameterInfo.
IsOut)
1266 arrayList2.
Add(parameterInfo);
1270 arrayList.
Add(parameterInfo);
1271 arrayList2.
Add(parameterInfo);
1275 arrayList.
Add(parameterInfo);
1279 arrayList.
Add(typeof(
object));
1280 arrayList2.
Add(typeof(IAsyncResult));
1282 MethodInfo[] methods = declaringType.GetMethods();
1287 if (methodInfo.
Name.Equals(value) && methodInfo.
ReturnType == typeFromHandle && CompareParameterList(arrayList, parameters2))
1289 beginMethod = methodInfo;
1291 else if (methodInfo.
Name.Equals(value2) && methodInfo.
ReturnType == returnType && CompareParameterList(arrayList2, parameters2))
1293 endMethod = methodInfo;
1296 if (beginMethod !=
null && endMethod !=
null)
1305 if (params1.
Count != params2.Length)
1310 foreach (
object item
in params1)
1314 if (parameterInfo2 !=
null)
1340 ServerIdentity serverIdentity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
1341 result = ((serverIdentity !=
null) ? serverIdentity.ServerType : RemotingConfigHandler.GetServerTypeForUri(URI));
1347 internal static void DomainUnloaded(
int domainID)
1349 IdentityHolder.FlushIdentityTable();
1350 CrossAppDomainSink.DomainUnloaded(domainID);
1354 internal static IntPtr GetServerContextForProxy(
object tp)
1356 ObjRef objRef =
null;
1359 return GetServerContextForProxy(tp, out objRef, out bSameDomain, out domainId);
1363 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
1364 internal static int GetServerDomainIdForProxy(
object tp)
1367 Identity identityObject = realProxy.IdentityObject;
1368 return identityObject.ObjectRef.GetServerDomainId();
1372 internal static void GetServerContextAndDomainIdForProxy(
object tp, out IntPtr contextId, out
int domainId)
1374 contextId = GetServerContextForProxy(tp, out ObjRef _, out
bool _, out domainId);
1378 private static IntPtr GetServerContextForProxy(
object tp, out ObjRef objRef, out
bool bSameDomain, out
int domainId)
1380 IntPtr result = IntPtr.Zero;
1382 bSameDomain =
false;
1387 Identity identityObject = realProxy.IdentityObject;
1388 if (identityObject !=
null)
1390 ServerIdentity serverIdentity = identityObject as ServerIdentity;
1391 if (serverIdentity !=
null)
1394 result = serverIdentity.ServerContext.InternalContextID;
1399 objRef = identityObject.ObjectRef;
1400 result = ((objRef ==
null) ? IntPtr.Zero : objRef.GetServerContext(out domainId));
1412 internal static Context GetServerContext(MarshalByRefObject obj)
1422 Identity identityObject = realProxy.IdentityObject;
1423 ServerIdentity serverIdentity = identityObject as ServerIdentity;
1424 if (serverIdentity !=
null)
1426 result = serverIdentity.ServerContext;
1433 private static object GetType(
object tp)
1437 Identity identityObject = realProxy.IdentityObject;
1438 if (identityObject !=
null && identityObject.ObjectRef !=
null && identityObject.ObjectRef.TypeInfo !=
null)
1440 IRemotingTypeInfo typeInfo = identityObject.ObjectRef.TypeInfo;
1441 string typeName = typeInfo.TypeName;
1442 if (typeName !=
null)
1444 result = InternalGetTypeFromQualifiedTypeName(typeName);
1451 internal static byte[] MarshalToBuffer(
object o,
bool crossRuntime)
1464 MarshalByRefObject marshalByRefObject = o as MarshalByRefObject;
1465 if (marshalByRefObject !=
null)
1467 ProxyAttribute proxyAttribute = ActivationServices.GetProxyAttribute(marshalByRefObject.GetType());
1480 binaryFormatter.
Serialize(memoryStream, o,
null, fCheck:
false);
1485 internal static object UnmarshalFromBuffer(
byte[] b,
bool crossRuntime)
1492 object obj = binaryFormatter.
Deserialize(serializationStream,
null, fCheck:
false);
1508 internal static object UnmarshalReturnMessageFromBuffer(
byte[] b,
IMethodCallMessage msg)
1531 if (realProxy is RemotingProxy && !realProxy.DoContextsMatch())
1535 StackBuilderSink stackBuilderSink =
new StackBuilderSink(target);
1540 internal static string DetermineDefaultQualifiedTypeName(
Type type)
1546 string xmlType =
null;
1547 string xmlTypeNamespace =
null;
1548 if (SoapServices.GetXmlTypeForInteropType(type, out xmlType, out xmlTypeNamespace))
1550 return "soap:" + xmlType +
", " + xmlTypeNamespace;
1556 internal static string GetDefaultQualifiedTypeName(RuntimeType type)
1558 RemotingTypeCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(type);
1559 return reflectionCachedData.QualifiedTypeName;
1562 internal static string InternalGetClrTypeNameFromQualifiedTypeName(
string qualifiedTypeName)
1564 if (qualifiedTypeName.Length > 4 &&
string.CompareOrdinal(qualifiedTypeName, 0,
"clr:", 0, 4) == 0)
1566 return qualifiedTypeName.Substring(4);
1571 private static int IsSoapType(
string qualifiedTypeName)
1573 if (qualifiedTypeName.Length > 5 &&
string.CompareOrdinal(qualifiedTypeName, 0,
"soap:", 0, 5) == 0)
1575 return qualifiedTypeName.IndexOf(
',', 5);
1581 internal static string InternalGetSoapTypeNameFromQualifiedTypeName(
string xmlTypeName,
string xmlTypeNamespace)
1583 if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, out
string typeNamespace, out
string assemblyName))
1587 string str = (typeNamespace ==
null || typeNamespace.Length <= 0) ? xmlTypeName : (typeNamespace +
"." + xmlTypeName);
1590 return str +
", " + assemblyName;
1599 internal static string InternalGetTypeNameFromQualifiedTypeName(
string qualifiedTypeName)
1601 if (qualifiedTypeName ==
null)
1603 throw new ArgumentNullException(
"qualifiedTypeName");
1605 string text = InternalGetClrTypeNameFromQualifiedTypeName(qualifiedTypeName);
1610 int num = IsSoapType(qualifiedTypeName);
1613 string xmlTypeName = qualifiedTypeName.Substring(5, num - 5);
1614 string xmlTypeNamespace = qualifiedTypeName.Substring(num + 2, qualifiedTypeName.Length - (num + 2));
1615 text = InternalGetSoapTypeNameFromQualifiedTypeName(xmlTypeName, xmlTypeNamespace);
1621 return qualifiedTypeName;
1625 internal static RuntimeType InternalGetTypeFromQualifiedTypeName(
string qualifiedTypeName,
bool partialFallback)
1627 if (qualifiedTypeName ==
null)
1629 throw new ArgumentNullException(
"qualifiedTypeName");
1631 string text = InternalGetClrTypeNameFromQualifiedTypeName(qualifiedTypeName);
1634 return LoadClrTypeWithPartialBindFallback(text, partialFallback);
1636 int num = IsSoapType(qualifiedTypeName);
1639 string text2 = qualifiedTypeName.Substring(5, num - 5);
1640 string xmlTypeNamespace = qualifiedTypeName.Substring(num + 2, qualifiedTypeName.Length - (num + 2));
1641 RuntimeType runtimeType = (RuntimeType)SoapServices.GetInteropTypeFromXmlType(text2, xmlTypeNamespace);
1642 if (runtimeType !=
null)
1646 text = InternalGetSoapTypeNameFromQualifiedTypeName(text2, xmlTypeNamespace);
1649 return LoadClrTypeWithPartialBindFallback(text, partialFallback:
true);
1652 return LoadClrTypeWithPartialBindFallback(qualifiedTypeName, partialFallback);
1656 internal static Type InternalGetTypeFromQualifiedTypeName(
string qualifiedTypeName)
1658 return InternalGetTypeFromQualifiedTypeName(qualifiedTypeName, partialFallback:
true);
1662 private static RuntimeType LoadClrTypeWithPartialBindFallback(
string typeName,
bool partialFallback)
1664 if (!partialFallback)
1666 return (RuntimeType)
Type.GetType(typeName, throwOnError:
false);
1668 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1669 return RuntimeTypeHandle.GetTypeByName(typeName, throwOnError:
false, ignoreCase:
false, reflectionOnly:
false, ref stackMark, loadTypeFromPartialName:
true);
1674 internal static extern bool CORProfilerTrackRemoting();
1678 internal static extern bool CORProfilerTrackRemotingCookie();
1682 internal static extern bool CORProfilerTrackRemotingAsync();
1686 internal static extern void CORProfilerRemotingClientSendingMessage(out Guid
id,
bool fIsAsync);
1690 internal static extern void CORProfilerRemotingClientReceivingReply(Guid
id,
bool fIsAsync);
1694 internal static extern void CORProfilerRemotingServerReceivingMessage(Guid
id,
bool fIsAsync);
1698 internal static extern void CORProfilerRemotingServerSendingReply(out Guid
id,
bool fIsAsync);
1704 [Obsolete(
"Use of this method is not recommended. The LogRemotingStage existed for internal diagnostic purposes only.")]
1711 internal static extern void ResetInterfaceCache(
object proxy);
static Thread CurrentThread
Gets the currently running thread.
Discovers the attributes of a parameter and provides access to parameter metadata.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
MethodBase MethodBase
Gets the T:System.Reflection.MethodBase of the called method.
Discovers the attributes of a method and provides access to method metadata.
Indicates that the current interface implementer is a reference to another object.
static void SetObjectUriForMarshal(MarshalByRefObject obj, string uri)
Sets the URI for the subsequent call to the M:System.Runtime.Remoting.RemotingServices....
LeaseState
Indicates the possible lease states of a lifetime lease.
Defines the method call return message interface.
Represents the construction call request of an object.
static Context DefaultContext
Gets the default context for the current application domain.
static bool IsMethodOverloaded(IMethodMessage msg)
Returns a Boolean value that indicates whether the method in the given message is overloaded.
static ObjRef Marshal(MarshalByRefObject Obj, string ObjURI, Type RequestedType)
Takes a T:System.MarshalByRefObject and converts it into an instance of the T:System....
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a specified T:System.Runtime.Serialization.SerializationInfo with the data needed to serial...
static void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
Serializes the specified marshal by reference object into the provided T:System.Runtime....
Defines the method call message interface.
static Type GetServerTypeForUri(string URI)
Returns the T:System.Type of the object with the specified URI.
bool IsInterface
Gets a value indicating whether the T:System.Type is an interface; that is, not a class or a value ty...
Discovers the attributes of a class constructor and provides access to constructor metadata.
Provides base functionality for proxies.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
abstract string AssemblyQualifiedName
Gets the assembly-qualified name of the type, which includes the name of the assembly from which this...
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
virtual Type ReturnType
Gets the return type of this method.
Provides a mechanism that synchronizes access to objects.
delegate void AsyncCallback(IAsyncResult ar)
References a method to be called when a corresponding asynchronous operation completes.
static ObjRef GetObjRefForProxy(MarshalByRefObject obj)
Returns the T:System.Runtime.Remoting.ObjRef that represents the remote object from the specified pro...
Stores all relevant information required to generate a proxy in order to communicate with a remote ob...
Defines an environment for the objects that are resident inside it and for which a policy can be enfo...
bool IsIn
Gets a value indicating whether this is an input parameter.
ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
Searches for a constructor whose parameters match the specified argument types and modifiers,...
static IMethodReturnMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage reqMsg)
Connects to the specified remote object, and executes the provided T:System.Runtime....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static IMessageSink GetEnvoyChainForProxy(MarshalByRefObject obj)
Returns a chain of envoy sinks that should be used when sending messages to the remote object represe...
Selects the remoting surrogate that can be used to serialize an object that derives from a T:System....
Represents type declarations for class types, interface types, array types, value types,...
Cer
Specifies a method's behavior when called within a constrained execution region.
static ObjRef Marshal(MarshalByRefObject Obj)
Takes a T:System.MarshalByRefObject, registers it with the remoting infrastructure,...
virtual byte [] GetBuffer()
Returns the array of unsigned bytes from which this stream was created.
static void LogRemotingStage(int stage)
Logs the stage in a remoting exchange to an external debugger.
virtual ObjRef CreateObjRef(Type requestedType)
Creates an object that contains all the relevant information required to generate a proxy used to com...
CallingConventions
Defines the valid calling conventions for a method.
SecurityAction
Specifies the security actions that can be performed using declarative security.
static void Enter(object obj)
Acquires an exclusive lock on the specified object.
Identifies a T:System.Runtime.Remoting.Messaging.IMethodReturnMessage that is returned after attempti...
Provides information about, and means to manipulate, the current environment and platform....
Represents the status of an asynchronous operation.
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Finds or creates a T:System.AppDomain.
static bool IsObjectOutOfAppDomain(object tp)
Returns a Boolean value that indicates whether the object specified by the given transparent proxy is...
static MethodBase GetMethodBaseFromMethodMessage(IMethodMessage msg)
Returns the method base from the given T:System.Runtime.Remoting.Messaging.IMethodMessage.
static bool IsObjectOutOfContext(object tp)
Returns a Boolean value that indicates whether the object represented by the given proxy is contained...
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Defines the underlying structure of all code access permissions.
A platform-specific type that is used to represent a pointer or a handle.
static object Connect(Type classToProxy, string url, object data)
Creates a proxy for a well-known object, given the T:System.Type, URL, and channel-specific data.
static void Exit(object obj)
Releases an exclusive lock on the specified object.
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Indicates that an object type requires a custom proxy.
Provides static methods to aid with remoting channel registration, resolution, and URL discovery....
Represents type declarations: class types, interface types, array types, value types,...
static GCHandle Alloc(object value)
Allocates a F:System.Runtime.InteropServices.GCHandleType.Normal handle for the specified object.
Defines utility methods for use by the .NET Framework remoting infrastructure.
object MethodSignature
Gets an object containing the method signature.
static object Connect(Type classToProxy, string url)
Creates a proxy for a well-known object, given the T:System.Type and URL.
Provides information about methods and constructors.
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
Provides a way to access a managed object from unmanaged memory.
string TypeName
Gets the full T:System.Type name of the specific object that the call is destined for.
MethodImplOptions
Defines the details of how a method is implemented.
static AppDomain GetDomain()
Returns the current domain in which the current thread is running.
virtual object GetTransparentProxy()
Returns the transparent proxy for the current instance of T:System.Runtime.Remoting....
Defines the method message interface.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
Searches for the specified method whose parameters match the specified argument types and modifiers,...
static string GetObjectUri(MarshalByRefObject obj)
Retrieves the URI for the specified object.
static object Unmarshal(ObjRef objectRef, bool fRefine)
Takes a T:System.Runtime.Remoting.ObjRef and creates a proxy object out of it, refining it to the typ...
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
string Uri
Gets the URI of the specific object that the call is destined for.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
static RealProxy GetRealProxy(object proxy)
Returns the real proxy backing the specified transparent proxy.
static bool IsOneWay(MethodBase method)
Returns a Boolean value that indicates whether the client that called the method specified in the giv...
static ObjRef Marshal(MarshalByRefObject Obj, string URI)
Converts the given T:System.MarshalByRefObject into an instance of the T:System.Runtime....
static string GetSessionIdForMethodMessage(IMethodMessage msg)
Retrieves a session ID for a message.
static object Unmarshal(ObjRef objectRef)
Takes a T:System.Runtime.Remoting.ObjRef and creates a proxy object out of it.
virtual RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
Creates an instance of a remoting proxy for a remote object described by the specified T:System....
bool IsMarshalByRef
Gets a value indicating whether the T:System.Type is marshaled by reference.
Defines the interface for a message sink.
bool IsOut
Gets a value indicating whether this is an output parameter.
static object GetLifetimeService(MarshalByRefObject obj)
Returns a lifetime service object that controls the lifetime policy of the specified object.
virtual Type ParameterType
Gets the Type of this parameter.
Consistency
Specifies a reliability contract.
string Name
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
StreamingContextStates
Defines a set of flags that specifies the source or destination context for the stream during seriali...
static bool Disconnect(MarshalByRefObject obj)
Stops an object from receiving any further messages through the registered remoting channels.
Provides information about a specific culture (called a locale for unmanaged code development)....
ConstructorInfo [] GetConstructors()
Returns all the public constructors defined for the current T:System.Type.
bool IsByRef
Gets a value indicating whether the T:System.Type is passed by reference.
A conditional operation, such as a > b ? a : b in C# or If(a > b, a, b) in Visual Basic.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
The exception that is thrown when binding to a member results in more than one member matching the bi...
static Context CurrentContext
Gets the current context in which the thread is executing.
string MethodName
Gets the name of the invoked method.
static IChannel [] RegisteredChannels
Gets a list of currently registered channels.
The exception that is thrown when something has gone wrong during remoting.
Provides a way to register, unregister, and obtain a list of tracking handlers.
abstract ParameterInfo [] GetParameters()
When overridden in a derived class, gets the parameters of the specified method or constructor.
virtual ObjRef CreateObjRef(Type requestedType)
Creates an T:System.Runtime.Remoting.ObjRef for the specified object type, and registers it with the ...
Provides a set of static methods and properties that provide support for compilers....
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Enables access to objects across application domain boundaries in applications that support remoting.
Creates and controls a thread, sets its priority, and gets its status.