You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VM: (bug) open virtual delegates compare equal but have different hash codes #134218
Two open delegates created over the same virtual slot (from Base.M and from Derived.M) behave inconsistently on main: Release reports Equals == true with different hash codes, violating the Equals/GetHashCode contract and breaking dictionary lookups; Checked reports Equals == false. .NET 10.0.12 is self-consistent.
In Release, Delegate.Equals treats matching _methodPtrAux virtual-dispatch stubs as equal, and that stub is keyed by slot, so Base.M and Derived.M produce the same stub. Delegate.GetHashCode instead hashes the MethodDesc, which stays distinct. Checked compiles out the _methodPtrAux shortcut and returns false from Equals.
Either way, Equals and GetHashCode must agree.
Regression?
Yes. .NET 10.0.12 reports Equals=True hashEq=True and finds the dictionary key.
Platform
Windows x64, CoreCLR main (Checked and Release); .NET 10.0.12 is unaffected.
@jkotas Should CreateDelegate normalize the derived case to the more concrete method when creating the delegate? I'd expect either that or for Equals to be false here since d1.Method == d2.Method would be.
var d1 = (Action)Delegate.CreateDelegate(typeof(Action), typeof(Base).GetMethod("M")!);
var d2 = (Action)Delegate.CreateDelegate(typeof(Action), typeof(Derived).GetMethod("M")!);
I would expect d1.Equals(d2) to be false. The two delegates are not pointing to the same method.
Activity
dotnet-policy-service commentedon Sep 18, 2026
Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.
MichalPetryka commentedon Sep 18, 2026
@jkotas Should
CreateDelegatenormalize the derived case to the more concrete method when creating the delegate? I'd expect either that or for Equals to be false here sinced1.Method == d2.Methodwould be.jkotas commentedon Sep 18, 2026
I would expect
d1.Equals(d2)to be false. The two delegates are not pointing to the same method.jkotas commentedon Sep 18, 2026
@MichalPetryka Could you please create a PR with the fix? This is regression from last release, so it is a backport candidate.
Remove open delegate Equals fastpath
Remove open delegate Equals fastpath (#134224)