object IObjectReference.GetRealObject(StreamingContext context) { if (this.m_realObject != null) { return(this.m_realObject); } if (this.m_realType == null) { return(this); } Stack stack = new Stack(); RuntimeType realType = this.m_realType; do { stack.Push(realType); realType = realType.BaseType as RuntimeType; }while (realType != typeof(object)); RuntimeConstructorInfo ctorInfo = null; RuntimeType t = null; do { t = realType; realType = stack.Pop() as RuntimeType; }while (ObjectManager.TryGetConstructor(realType, out ctorInfo) && ctorInfo.IsSecurityCritical); ctorInfo = ObjectManager.GetConstructor(t); object uninitializedObject = FormatterServices.GetUninitializedObject(this.m_realType); ctorInfo.SerializationInvoke(uninitializedObject, this.m_savedSerializationInfo, context); this.m_savedSerializationInfo = null; this.m_realType = null; this.m_realObject = uninitializedObject; return(uninitializedObject); }
internal void CompleteISerializableObject(object obj, SerializationInfo info, StreamingContext context) { if (obj == null) { throw new ArgumentNullException("obj"); } if (!(obj is ISerializable)) { throw new ArgumentException(Environment.GetResourceString("Serialization_NotISer")); } RuntimeConstructorInfo runtimeConstructorInfo = null; RuntimeType runtimeType = (RuntimeType)obj.GetType(); try { if (runtimeType == ObjectManager.TypeOfWindowsIdentity && this.m_isCrossAppDomain) { runtimeConstructorInfo = WindowsIdentity.GetSpecialSerializationCtor(); } else { runtimeConstructorInfo = ObjectManager.GetConstructor(runtimeType); } } catch (Exception innerException) { throw new SerializationException(Environment.GetResourceString("Serialization_ConstructorNotFound", new object[] { runtimeType }), innerException); } runtimeConstructorInfo.SerializationInvoke(obj, info, context); }
object IObjectReference.GetRealObject(StreamingContext context) { if (this.m_realObject != null) { return(this.m_realObject); } if (this.m_realType == (RuntimeType)null) { return((object)this); } Stack stack = new Stack(); RuntimeType runtimeType = this.m_realType; do { stack.Push((object)runtimeType); runtimeType = runtimeType.BaseType as RuntimeType; }while ((Type)runtimeType != typeof(object)); RuntimeType t; RuntimeConstructorInfo serializationCtor; do { t = runtimeType; runtimeType = stack.Pop() as RuntimeType; serializationCtor = runtimeType.GetSerializationCtor(); }while ((ConstructorInfo)serializationCtor != (ConstructorInfo)null && serializationCtor.IsSecurityCritical); RuntimeConstructorInfo constructor = ObjectManager.GetConstructor(t); object uninitializedObject = FormatterServices.GetUninitializedObject((Type)this.m_realType); constructor.SerializationInvoke(uninitializedObject, this.m_savedSerializationInfo, context); this.m_savedSerializationInfo = (SerializationInfo)null; this.m_realType = (RuntimeType)null; this.m_realObject = uninitializedObject; return(uninitializedObject); }
object IObjectReference.GetRealObject(StreamingContext context) { // If we've already deserialized the real object, use that rather than deserializing it again if (m_realObject != null) { return(m_realObject); } // If we don't have a real type to deserialize, then this is really a SafeSerializationManager // and we don't need to rebuild the object that we're standing in for. if (m_realType == null) { return(this); } // Look for the last type in GetRealType's inheritance hierarchy which implements a critical // deserialization constructor. This will be the object that we use as the deserialization // construction type to initialize via standard ISerializable semantics // First build up the chain starting at the type below Object and working to the real type we // serialized. Stack inheritanceChain = new Stack(); RuntimeType currentType = m_realType; do { inheritanceChain.Push(currentType); currentType = currentType.BaseType as RuntimeType; }while (currentType != typeof(object)); // Now look for the first type that does not implement the ISerializable .ctor. When we find // that, previousType will point at the last type that did implement the .ctor. We require that // the .ctor we invoke also be non-transparent RuntimeConstructorInfo serializationCtor = null; RuntimeType previousType = null; do { previousType = currentType; currentType = inheritanceChain.Pop() as RuntimeType; serializationCtor = currentType.GetSerializationCtor(); }while (serializationCtor != null && serializationCtor.IsSecurityCritical); // previousType is the last type that did implement the deserialization .ctor before the first // type that did not, so we'll grab it's .ctor to use for deserialization. BCLDebug.Assert(previousType != null, "We should have at least one inheritance from the base type"); serializationCtor = ObjectManager.GetConstructor(previousType); // Allocate an instance of the final type and run the selected .ctor on that instance to get the // standard ISerializable initialization done. object deserialized = FormatterServices.GetUninitializedObject(m_realType); serializationCtor.SerializationInvoke(deserialized, m_savedSerializationInfo, context); m_savedSerializationInfo = null; m_realType = null; // Save away the real object that was deserialized so that we can fill it in later, and return // it back as the object that should result from the final deserialization. m_realObject = deserialized; return(deserialized); }
internal void CompleteISerializableObject(object obj, SerializationInfo info, StreamingContext context) { if (obj == null) { throw new ArgumentNullException("obj"); } if (!(obj is ISerializable)) { throw new ArgumentException(Environment.GetResourceString("Serialization_NotISer")); } RuntimeType t = (RuntimeType)obj.GetType(); RuntimeConstructorInfo runtimeConstructorInfo; try { runtimeConstructorInfo = !(t == ObjectManager.TypeOfWindowsIdentity) || !this.m_isCrossAppDomain ? ObjectManager.GetConstructor(t) : WindowsIdentity.GetSpecialSerializationCtor(); } catch (Exception ex) { throw new SerializationException(Environment.GetResourceString("Serialization_ConstructorNotFound", (object)t), ex); } runtimeConstructorInfo.SerializationInvoke(obj, info, context); }