System.Runtime.Serialization.ObjectManager.ResolveObjectReference C# (CSharp) Method

ResolveObjectReference() private method

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 ResolveObjectReference ( ObjectHolder holder ) : bool
holder ObjectHolder
return bool
        private bool ResolveObjectReference(ObjectHolder holder)
        {
            object tempObject;
            Debug.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;
                    holder.SetObjectValue(((IObjectReference)(holder.ObjectValue)).GetRealObject(_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);
                        return false;
                    }
                    if (depthCount++ == MaxReferenceDepth)
                    {
                        throw new SerializationException(SR.Serialization_TooManyReferences);
                    }
                } while ((holder.ObjectValue is IObjectReference) && (tempObject != holder.ObjectValue));
            }
            catch (NullReferenceException)
            {
                return false;
            }

            holder.IsIncompleteObjectReference = false;
            DoNewlyRegisteredObjectFixups(holder);
            return true;
        }