diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index 2e4179eed9c3a0..fd5e81d085f153 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -2793,13 +2793,6 @@ MethodDesc* COMDelegate::GetDelegateCtor(TypeHandle delegateType, MethodDesc *pT // associated with the instantiation. BOOL fMaybeCollectibleAndStatic = FALSE; - // Do not allow static methods with [UnmanagedCallersOnlyAttribute] to be a delegate target. - // A method marked UnmanagedCallersOnly is special and allowing it to be delegate target will destabilize the runtime. - if (pTargetMethod->HasUnmanagedCallersOnlyAttribute()) - { - COMPlusThrow(kNotSupportedException, W("NotSupported_UnmanagedCallersOnlyTarget")); - } - if (isStatic) { // When this method is called and the method being considered is shared, we typically diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 35ff2396d179b8..6082e0ec3f6b86 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -3092,9 +3092,6 @@ Module argument must be a ModuleBuilder. - - Methods with UnmanagedCallersOnlyAttribute cannot be used as delegate target. - No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. diff --git a/src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il b/src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il index 50edd29ba448bf..1e4f4ad1f111e2 100644 --- a/src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il +++ b/src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il @@ -101,47 +101,6 @@ ret } - .method public hidebysig static - int32 ManagedDoubleCallback ( - int32 n - ) cil managed - { - .custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute::.ctor() = ( - 01 00 00 00 - ) - .maxstack 1 - - nop - ldarg.0 - call int32 InvalidCSharp.CallingUnmanagedCallersOnlyDirectly::DoubleImpl(int32) - ret - } - - .method private hidebysig static - int32 DoubleImpl ( - int32 n - ) cil managed - { - .maxstack 2 - - nop - ldc.i4.2 - ldarg.0 - mul - ret - } - - .method public hidebysig static - class [System.Runtime]System.Func`2 GetDoubleDelegate () cil managed - { - .maxstack 8 - - ldnull - ldftn int32 InvalidCSharp.CallingUnmanagedCallersOnlyDirectly::ManagedDoubleCallback(int32) - newobj instance void class [System.Runtime]System.Func`2::.ctor(object, native int) - ret - } - .method public hidebysig static pinvokeimpl("UnmanagedCallersOnlyDll" as "DoesntExist" winapi) int32 PInvokeMarkedWithUnmanagedCallersOnly ( int32 n diff --git a/src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs b/src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs index 702970b956b4a2..e873377db4204c 100644 --- a/src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs +++ b/src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs @@ -51,22 +51,6 @@ public static void TestUnmanagedCallersOnlyValid_ThrowException() Assert.Equal(-1, UnmanagedCallersOnlyDll.CallManagedProcCatchException((IntPtr)(delegate* unmanaged)&CallbackThrows, n)); } - [Fact] - public static void NegativeTest_ViaDelegate() - { - Console.WriteLine($"Running {nameof(NegativeTest_ViaDelegate)}..."); - - // Try invoking method directly - Assert.Throws(() => { CallAsDelegate(); }); - - // Local function to delay exception thrown during JIT - void CallAsDelegate() - { - Func invoker = CallingUnmanagedCallersOnlyDirectly.GetDoubleDelegate(); - invoker(0); - } - } - [Fact] public static void NegativeTest_NonStaticMethod() {