System.Web.Script.Serialization.JavaScriptSerializer - prevent serializing a property

Issue:

Use the .Net JavaScriptSerializer  to serialize an object but due to circular references need to prevent from those properties from being serialized.

Solution:

In order to ignore certain properties from getting serialized, simply add the ScriptIgnoreAttribute attribute to the property:

        [ScriptIgnore]
        public virtual MyClassCausingCircularRefError MyProperty
        {
            get { return _privateField; }
        }

Twitter