Why does Object.Equals() return false for identical anonymous types when they're instantiated from different assemblies?
<p>I have some code that maps strongly-typed business objects into anonymous types, which are then serialized into JSON and exposed via an API.</p>

<p>After restructuring my solution into separate projects, some of my tests started to fail. I've done a bit of digging and it turns out that <code>Object.Equals</code> behaves differently on anonymous types that are returned by code from a different assembly - and I'm not sure why, or what I can do to work around it.</p>

<p>There's full repro code at <a href="https://github.com/dylanbeattie/AnonymousTypeEquality">https://github.com/dylanbeattie/AnonymousTypeEquality</a> but the bit that's actually breaking is below. This code is in the Tests project:</p>

<pre><code>[TestFixture]
public class Tests {
    [Test]
    public void BothInline() {
        var a = new { name = "test", value = 123 };
        var b = new { name = "test", value = 123 };
        Assert.That(Object.Equals(a,b)); // passes
    }

    [Test]
    public void FromLocalMethod() {
        var a = new { name = "test", value = 123 };
        var b = MakeObject("test", 123);
        Assert.That(Object.Equals(a, b)); // passes
    }

    [Test]
    public void FromOtherNamespace() {
        var a = new { name = "test", value = 123 };
        var b = OtherNamespaceClass.MakeObject("test", 123);
        Assert.That(Object.Equals(a, b)); // passes
    }


    [Test]
    public void FromOtherClass() {
        var a = new { name = "test", value = 123 };
        var b = OtherClass.MakeObject("test", 123);

        /* This is the test that fails, and I cannot work out why */
        Assert.That(Object.Equals(a, b));
    }

    private object MakeObject(string name, int value) {
        return new { name, value };
    }
}
</code></pre>

<p>and then there is a separate class library in the solution containing only this:</p>

<pre><code>namespace OtherClasses {
  public static class OtherClass {
    public static object MakeObject(string name, int value) {
      return new { name, value };
    }
  }  
}
</code></pre>

<p>According to <a href="https://msdn.microsoft.com/en-GB/library/bb397696.aspx">MSDN</a>, "two instances of the <strong>same anonymous type</strong> are equal only if all their properties are equal." (my emphasis) - so what controls whether two instances are of the <strong>same</strong> anonymous type for comparison purposes? My two instances have equal hash codes, and both appear to be <code>&lt;>f__AnonymousType0`2[System.String,System.Int32]</code> - but I'm guessing that equality for anonymous types must take the fully qualified type name into account and therefore moving code into a different assembly can break things. Anyone got a definitive source / link on exactly how this is implemented? </p>