diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index abee693c98e8e..a500c76603f18 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -2600,11 +2600,6 @@ bool COMDelegate::IsMethodDescCompatible(TypeHandle thFirstArg, if (flags & DBF_InstanceMethodOnly && pTargetMethod->IsStatic()) return false; - // we don't allow you to bind to methods on Nullable because the unboxing stubs don't know how to - // handle this case. - if (!pTargetMethod->IsStatic() && Nullable::IsNullableType(pTargetMethod->GetMethodTable())) - return false; - // Get signatures for the delegate invoke and target methods. MetaSig sigInvoke(pInvokeMethod, thDelegate); MetaSig sigTarget(pTargetMethod, thExactMethodType); diff --git a/src/libraries/System.Runtime/tests/System/DelegateTests.cs b/src/libraries/System.Runtime/tests/System/DelegateTests.cs index 055fd8274e266..cadeabb5dc692 100644 --- a/src/libraries/System.Runtime/tests/System/DelegateTests.cs +++ b/src/libraries/System.Runtime/tests/System/DelegateTests.cs @@ -1101,6 +1101,28 @@ public static void CreateDelegate9_Type_Null() Assert.Null(ex.InnerException); Assert.NotNull(ex.Message); } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)] + [Fact] + public static void CreateDelegate10_Nullable_Method() + { + int? num = 123; + MethodInfo mi = typeof(int?).GetMethod("ToString"); + NullableIntToString toString = (NullableIntToString)Delegate.CreateDelegate( + typeof(NullableIntToString), mi); + string s = toString(ref num); + Assert.Equal(num.ToString(), s); + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/49839", TestRuntimes.Mono)] + [Fact] + public static void CreateDelegate10_Nullable_ClosedDelegate() + { + int? num = 123; + MethodInfo mi = typeof(int?).GetMethod("ToString"); + AssertExtensions.Throws( + () => Delegate.CreateDelegate(typeof(NullableIntToString), num, mi)); + } #endregion Tests #region Test Setup @@ -1207,6 +1229,8 @@ public interface Iface public delegate void D(C c); public delegate int E(C c); + + delegate string NullableIntToString(ref int? obj); #endregion Test Setup } }