Skip to content

Proxy created with CreateClassProxyWithTarget returns false for Equals on itself #652

@Gonyoda

Description

@Gonyoda

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions