private bool ResolveObjectReference(ObjectHolder holder) { int num = 0; try { object objectValue; do { objectValue = holder.ObjectValue; holder.SetObjectValue(((IObjectReference)holder.ObjectValue).GetRealObject(this.m_context), this); if (holder.ObjectValue == null) { holder.SetObjectValue(objectValue, this); return(false); } if (num++ == 100) { throw new SerializationException(Environment.GetResourceString("Serialization_TooManyReferences")); } }while ((holder.ObjectValue is IObjectReference) && (objectValue != holder.ObjectValue)); } catch (NullReferenceException) { return(false); } holder.IsIncompleteObjectReference = false; this.DoNewlyRegisteredObjectFixups(holder); return(true); }
private void FixupSpecialObject(ObjectHolder holder) { ISurrogateSelector selector = null; if (holder.HasSurrogate) { ISerializationSurrogate surrogate = holder.Surrogate; object obj = surrogate.SetObjectData(holder.ObjectValue, holder.SerializationInfo, this.m_context, selector); if (obj != null) { if (!holder.CanSurrogatedObjectValueChange && obj != holder.ObjectValue) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NotCyclicallyReferenceableSurrogate"), surrogate.GetType().FullName)); } holder.SetObjectValue(obj, this); } holder.m_surrogate = null; holder.SetFlags(); } else { this.CompleteISerializableObject(holder.ObjectValue, holder.SerializationInfo, this.m_context); } holder.SerializationInfo = null; holder.RequiresSerInfoFixup = false; if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed) { this.DoValueTypeFixup(null, holder, holder.ObjectValue); } this.DoNewlyRegisteredObjectFixups(holder); }
private bool ResolveObjectReference(ObjectHolder holder) { int num = 0; try { object objectValue; for (;;) { objectValue = holder.ObjectValue; holder.SetObjectValue(((IObjectReference)holder.ObjectValue).GetRealObject(this.m_context), this); if (holder.ObjectValue == null) { break; } if (num++ == 100) { goto Block_3; } if (!(holder.ObjectValue is IObjectReference) || objectValue == holder.ObjectValue) { goto IL_69; } } holder.SetObjectValue(objectValue, this); return(false); Block_3: throw new SerializationException(Environment.GetResourceString("Serialization_TooManyReferences")); IL_69 :; } catch (NullReferenceException) { return(false); } holder.IsIncompleteObjectReference = false; this.DoNewlyRegisteredObjectFixups(holder); return(true); }
/*============================ResolveObjectReference============================ **Action:Unfortunately, an ObjectReference could actually be a reference to another ** object reference and we don't know how far we have to tunnel until we can find the real object. While ** we're still getting instances of IObjectReference back and we're still getting new objects, keep calling ** GetRealObject. Once we've got the new object, take care of all of the fixups ** that we can do now that we've got it. ==============================================================================*/ private bool ResolveObjectReference(ObjectHolder holder) { Object tempObject; BCLDebug.Assert(holder.IsIncompleteObjectReference,"holder.IsIncompleteObjectReference"); //In the pathological case, an Object implementing IObjectReference could return a reference //to a different object which implements IObjectReference. This makes us vulnerable to a //denial of service attack and stack overflow. If the depthCount becomes greater than //MaxReferenceDepth, we'll throw a SerializationException. int depthCount = 0; //We wrap this in a try/catch block to handle the case where we're trying to resolve a chained //list of object reference (e.g. an IObjectReference can't resolve itself without some information //that's currently missing from the graph). We'll catch the NullReferenceException and come back //and try again later. The downside of this scheme is that if the object actually needed to throw //a NullReferenceException, it's being caught and turned into a SerializationException with a //fairly cryptic message. try { do { tempObject = holder.ObjectValue; BCLDebug.Trace("SER", "[ResolveObjectReference]ID: ", holder.m_id); BCLDebug.Trace("SER", "[ResolveObjectReference]HasISerializable: ", holder.HasISerializable); holder.SetObjectValue(((IObjectReference)(holder.ObjectValue)).GetRealObject(m_context), this); //The object didn't yet have enough information to resolve the reference, so we'll //return false and the graph walker should call us back again after more objects have //been resolved. if (holder.ObjectValue==null) { holder.SetObjectValue(tempObject, this); BCLDebug.Trace("SER", "Object: ", holder.m_id, " did NOT have enough information to resolve the IObjectReference."); return false; } if (depthCount++==MaxReferenceDepth) { throw new SerializationException(Environment.GetResourceString("Serialization_TooManyReferences")); } } while ((holder.ObjectValue is IObjectReference) && (tempObject!=holder.ObjectValue)); } catch (NullReferenceException) { BCLDebug.Trace("SER", "[ResolveObjectReference]Caught exception trying to call GetRealObject."); return false; } BCLDebug.Trace("SER", "Object: ", holder.m_id, " resolved the IObjectReference."); holder.IsIncompleteObjectReference=false; DoNewlyRegisteredObjectFixups(holder); return true; }
[System.Security.SecurityCritical] // auto-generated private void FixupSpecialObject(ObjectHolder holder) { ISurrogateSelector uselessSelector=null; Contract.Assert(holder.RequiresSerInfoFixup,"[ObjectManager.FixupSpecialObject]holder.HasSurrogate||holder.HasISerializable"); if (holder.HasSurrogate) { ISerializationSurrogate surrogate = holder.Surrogate; Contract.Assert(surrogate!=null,"surrogate!=null"); object returnValue = surrogate.SetObjectData(holder.ObjectValue, holder.SerializationInfo, m_context, uselessSelector); if (returnValue != null) { if (!holder.CanSurrogatedObjectValueChange && returnValue != holder.ObjectValue) throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NotCyclicallyReferenceableSurrogate"), surrogate.GetType().FullName)); holder.SetObjectValue(returnValue, this); } holder.m_surrogate = null; holder.SetFlags(); } else { //Set the object data Contract.Assert(holder.ObjectValue is ISerializable,"holder.m_object is ISerializable"); BCLDebug.Trace("SER","[ObjectManager.FixupSpecialObject]Fixing up ISerializable object ",holder.ObjectValue," with id ",holder.m_id); CompleteISerializableObject(holder.ObjectValue, holder.SerializationInfo, m_context); } //Clear anything that we know that we're not going to need. holder.SerializationInfo=null; holder.RequiresSerInfoFixup = false; // For value types, fixups would have been done. So the newly fixed object must be copied // to its container. if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed){ DoValueTypeFixup(null, holder, holder.ObjectValue); } DoNewlyRegisteredObjectFixups(holder); }
private bool ResolveObjectReference(ObjectHolder holder) { int num = 0; try { object objectValue; do { objectValue = holder.ObjectValue; holder.SetObjectValue(((IObjectReference) holder.ObjectValue).GetRealObject(this.m_context), this); if (holder.ObjectValue == null) { holder.SetObjectValue(objectValue, this); return false; } if (num++ == 100) { throw new SerializationException(Environment.GetResourceString("Serialization_TooManyReferences")); } } while ((holder.ObjectValue is IObjectReference) && (objectValue != holder.ObjectValue)); } catch (NullReferenceException) { return false; } holder.IsIncompleteObjectReference = false; this.DoNewlyRegisteredObjectFixups(holder); return true; }
private void FixupSpecialObject(ObjectHolder holder) { ISurrogateSelector selector = null; if (holder.HasSurrogate) { ISerializationSurrogate surrogate = holder.Surrogate; object obj2 = surrogate.SetObjectData(holder.ObjectValue, holder.SerializationInfo, this.m_context, selector); if (obj2 != null) { if (!holder.CanSurrogatedObjectValueChange && (obj2 != holder.ObjectValue)) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NotCyclicallyReferenceableSurrogate"), new object[] { surrogate.GetType().FullName })); } holder.SetObjectValue(obj2, this); } holder.m_surrogate = null; holder.SetFlags(); } else { this.CompleteISerializableObject(holder.ObjectValue, holder.SerializationInfo, this.m_context); } holder.SerializationInfo = null; holder.RequiresSerInfoFixup = false; if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed) { this.DoValueTypeFixup(null, holder, holder.ObjectValue); } this.DoNewlyRegisteredObjectFixups(holder); }
private void FixupSpecialObject(ObjectHolder holder) { ISurrogateSelector uselessSelector=null; BCLDebug.Assert(holder.RequiresSerInfoFixup,"[ObjectManager.FixupSpecialObject]holder.HasSurrogate||holder.HasISerializable"); if (holder.HasSurrogate) { ISerializationSurrogate surrogate = holder.Surrogate; BCLDebug.Assert(surrogate!=null,"surrogate!=null"); object returnValue = surrogate.SetObjectData(holder.ObjectValue, holder.SerializationInfo, m_context, uselessSelector); if (returnValue != null) holder.SetObjectValue(returnValue, this); holder.m_surrogate = null; holder.SetFlags(); } else { //Set the object data BCLDebug.Assert(holder.ObjectValue is ISerializable,"holder.m_object is ISerializable"); BCLDebug.Trace("SER","[ObjectManager.FixupSpecialObject]Fixing up ISerializable object ",holder.ObjectValue," with id ",holder.m_id); CompleteISerializableObject(holder.ObjectValue, holder.SerializationInfo, m_context); } //Clear anything that we know that we're not going to need. holder.SerializationInfo=null; holder.RequiresSerInfoFixup = false; // For value types, fixups would have been done. So the newly fixed object must be copied // to its container. if (holder.RequiresValueTypeFixup && holder.ValueTypeFixupPerformed){ DoValueTypeFixup(null, holder, holder.ObjectValue); } DoNewlyRegisteredObjectFixups(holder); }