ProxyGenerator.CreateClassProxyWithTarget returns a proxy instance p where p.Equals(p) returns false.
I can't find any documentation or code to indicate why this happens. We recently updated from 4.4.1 to 5.1.1 and noticed this new behavior/issue with proxy equality. Below is a simple test to demonstrate the error.
Why does p.Equals(p) return false?
public class SomeClass
{
public virtual string Value { get; set; }
}
[Fact]
public void ProxyClassEqualsBug()
{
var entity = new SomeClass();
var entityType = entity.GetType();
ProxyGenerator proxyGen = new();
var proxy = proxyGen.CreateClassProxyWithTarget(entityType, entity);
Assert.True(entity == entity);
Assert.True(entity.Equals(entity));
Assert.True(proxy == proxy);
Assert.True(proxy.Equals(proxy)); // fails
}