diff --git a/src/libraries/System.Runtime/tests/System/DelegateTests.cs b/src/libraries/System.Runtime/tests/System/DelegateTests.cs index 35ee59b921132..055fd8274e266 100644 --- a/src/libraries/System.Runtime/tests/System/DelegateTests.cs +++ b/src/libraries/System.Runtime/tests/System/DelegateTests.cs @@ -619,6 +619,10 @@ public static void CreateDelegate2() e = (E)Delegate.CreateDelegate(typeof(E), new C(), "DoExecute"); Assert.NotNull(e); Assert.Equal(102, e(new C())); + + e = (E)Delegate.CreateDelegate(typeof(E), new B() { field = 42 }, "GetField"); + Assert.NotNull(e); + Assert.Equal(42, e(new C())); } [Fact] @@ -1103,6 +1107,7 @@ public static void CreateDelegate9_Type_Null() public class B { + public int field; public virtual string retarg3(string s) { @@ -1136,6 +1141,11 @@ public int StartExecute(C c, B b) { return 3; } + + public int GetField(C c) + { + return field; + } } public class C : B, Iface diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs index af5a59415591a..faf349979a6a8 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -177,7 +177,7 @@ public static Delegate CreateDelegate(Type type, object? firstArgument, MethodIn return null; } - return CreateDelegate_internal(type, null, info, throwOnBindFailure); + return CreateDelegate_internal(type, target, info, throwOnBindFailure); } [RequiresUnreferencedCode("The target method might be removed")]