diff --git a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs index b27d21da100350..d0db9dc6ee077c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs @@ -212,14 +212,6 @@ public sealed override unsafe bool Equals([NotNullWhen(true)] object? obj) // unmanaged if (IsUnmanagedFunctionPtr) return other.IsUnmanagedFunctionPtr && _methodPtrAux == other._methodPtrAux; - - // Under cached interface dispatch we might see the shared CID_VirtualOpenDelegateDispatch stub. - // Fallback to desc comparison in such case for correctness. -#if !FEATURE_CACHED_INTERFACE_DISPATCH - // both delegates are open - if (_methodPtrAux == other._methodPtrAux) - return true; -#endif } // It's possible that the method pointer was JITted in one delegate but not the other. diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs index 6494af3a1341cd..c0a2037e79ce3c 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs @@ -485,6 +485,15 @@ private static void IntIntMethod(int expected, int actual) Assert.Equal(expected, actual); } + [Fact] + public static void DifferentMethodForDerivedBase() + { + var d1 = (Action)Delegate.CreateDelegate(typeof(Action), typeof(Base).GetMethod("M")!); + var d2 = (Action)Delegate.CreateDelegate(typeof(Action), typeof(Derived).GetMethod("M")!); + Assert.False(d1.Equals(d2)); + Assert.False(d1.Method.Equals(d2.Method)); + } + [Fact] public static void SameMethodObtainedViaDelegateAndReflectionAreSameForClass() { @@ -571,6 +580,9 @@ internal virtual void M1() { } internal virtual void M2() { } } + class Base { public virtual void M() { } } + class Derived : Base { public override void M() { } } + private delegate void IntIntDelegate(int expected, int actual); private delegate void IntIntDelegateWithDefault(int expected, int actual = 7);