title: Why doesn't reference loop detection use reference equality?
body: <p>When serializing the object below, Json.Net detects a self-referencing loop and throws an exception.</p>
  
  <p>The class has two important features:</p>
  
  <ul>
  <li>it has a self-referential property, <code>Child</code></li>
  <li>it overrides <code>Equals()</code> and <code>GetHashCode()</code></li>
  </ul>
  
  
  
  <pre><code>public class Foo
  {
      public int Value { get; set; }
  
      public Foo Child { get; set; }
  
      public override bool Equals(object obj) =&gt; (obj as Foo).Value == this.Value;
  
      public override int GetHashCode() =&gt; this.Value.GetHashCode();
  }
  
  ...
  
  var foo = new Foo { Value = 42, Child = new Foo { Value = 42 } };
  JsonConvert.SerializeObject(foo); // Throws JsonSerializationException
  </code></pre>
  
  <p>It appears that Json.Net uses the override of <code>Equals()</code> to detect the reference loop (confirmed by debugging). But there is no loop here.</p>
  
  <p><strong>Why doesn't it use <em>reference</em> equality to check for a reference loop?</strong></p>
  
  <p>I found <a href="https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json.Tests/Serialization/ReferenceLoopHandlingTests.cs#L271" rel="nofollow noreferrer">a test</a> demonstrating that one can supply a different <code>EqualityComparer</code> which does use reference equality, but I'm interested to know why that isn't the default behaviour.</p>