Overriding Equals/GetHashCode on proxy generation hook

May 27, 2015 ยท View on GitHub

Equals/GetHashCode

One of the most common mistakes when it comes to DynamicProxy is not overriding Equals/GetHashCode methods on proxy generation hooks, which means you're giving up caching and that in turn coupled with bugs in BCL means performance hit (plus increased memory consumption).

Solution

Solution is very simple, and there's no exceptions to this rule โ€“ always override Equals/GetHashCode methods on all your classes implementing IProxyGenerationHook.

See also