Amnesia.SerializationUtil.EnableCyclicalReferences C# (CSharp) Method

EnableCyclicalReferences() public static method

Wraps an ISerializationSurrogate surrogate with special one to enable cyclical references during serialization if hotfix http://support.microsoft.com/kb/931634, or later is installed. Wrapping the surrogate should fix the "The object with ID X was referenced in a fixup but does not exist." error that occurs during deserialization.
public static EnableCyclicalReferences ( ISerializationSurrogate surrogate ) : ISerializationSurrogate
surrogate ISerializationSurrogate
return ISerializationSurrogate
        public static ISerializationSurrogate EnableCyclicalReferences(ISerializationSurrogate surrogate)
        {
            // Look for the FormatterServices.GetSurrogateForCyclicalReference() method
            // This method cannot be called directly because it may not exist in all environments and currently
            // only exists on the Server-version of Windows.
            foreach (MethodInfo method in typeof(FormatterServices).GetMethods(BindingFlags.Public | BindingFlags.Static))
            {
                if (method.Name == "GetSurrogateForCyclicalReference")
                {
                    return (ISerializationSurrogate)method.Invoke(null, new object[] { surrogate });
                }
            }

            return surrogate;
        }