diff --git a/src/libraries/Common/src/Interop/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Interop.Ldap.cs index 512242230093ff..5277ffe947ac43 100644 --- a/src/libraries/Common/src/Interop/Interop.Ldap.cs +++ b/src/libraries/Common/src/Interop/Interop.Ldap.cs @@ -244,9 +244,11 @@ public void FromManaged(LdapReferralCallback managed) { _managed = managed; _native.sizeofcallback = sizeof(Native); +#pragma warning disable CA1416 // This call site is reachable on all platforms. _native.query = managed.query is not null ? Marshal.GetFunctionPointerForDelegate(managed.query) : IntPtr.Zero; _native.notify = managed.notify is not null ? Marshal.GetFunctionPointerForDelegate(managed.notify) : IntPtr.Zero; _native.dereference = managed.dereference is not null ? Marshal.GetFunctionPointerForDelegate(managed.dereference) : IntPtr.Zero; +#pragma warning restore CA1416 } public Native ToUnmanaged() => _native; diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index ebdd48c679fc97..4733a219d4b0d8 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -33,6 +33,7 @@ public static partial class PlatformDetection public static bool IsNotMonoInterpreter => !IsMonoInterpreter; public static bool IsMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") == "aot"; public static bool IsNotMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") != "aot"; + public static bool IsNotMonoAOTOrBrowser => IsNotMonoAOT && !IsBrowser; public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported; public static bool IsNotNativeAot => !IsNativeAot; public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")); diff --git a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs index 786ab50e0742be..6d5f5592c58bf7 100644 --- a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs +++ b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs @@ -671,7 +671,9 @@ private unsafe void Initialize() Interop.User32.WNDCLASS windowClass = new Interop.User32.WNDCLASS { hbrBackground = (IntPtr)(Interop.User32.COLOR_WINDOW + 1), +#pragma warning disable CA1416 // This call site is reachable on all platforms. lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProc), +#pragma warning restore CA1416 lpszClassName = className, hInstance = hInstance }; diff --git a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs index feb7274616730d..2a7d6c92d08770 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs @@ -143,7 +143,9 @@ internal unsafe OleDbHResult InitializeAndCreateSession(OleDbConnectionString co // since the delegate lifetime is longer than the original instance used to create it // we double check before each usage to verify the delegates function pointer +#pragma warning disable CA1416 // This call site is reachable on all platforms. if ((null == QueryInterface) || (method != Marshal.GetFunctionPointerForDelegate(QueryInterface))) +#pragma warning restore CA1416 { QueryInterface = Marshal.GetDelegateForFunctionPointer(method); constr.DangerousDataSourceIUnknownQueryInterface = QueryInterface; @@ -160,7 +162,9 @@ internal unsafe OleDbHResult InitializeAndCreateSession(OleDbConnectionString co // since the delegate lifetime is longer than the original instance used to create it // we double check before each usage to verify the delegates function pointer +#pragma warning disable CA1416 // This call site is reachable on all platforms. if ((null == Initialize) || (method != Marshal.GetFunctionPointerForDelegate(Initialize))) +#pragma warning restore CA1416 { Initialize = Marshal.GetDelegateForFunctionPointer(method); constr.DangerousIDBInitializeInitialize = Initialize; @@ -189,7 +193,9 @@ internal unsafe OleDbHResult InitializeAndCreateSession(OleDbConnectionString co // since the delegate lifetime is longer than the original instance used to create it // we double check before each usage to verify the delegates function pointer +#pragma warning disable CA1416 // This call site is reachable on all platforms. if ((null == CreateSession) || (method != Marshal.GetFunctionPointerForDelegate(CreateSession))) +#pragma warning restore CA1416 { CreateSession = Marshal.GetDelegateForFunctionPointer(method); constr.DangerousIDBCreateSessionCreateSession = CreateSession; @@ -388,7 +394,9 @@ internal void VerifyIDBCreateCommand(OleDbConnectionString constr) // since the delegate lifetime is longer than the original instance used to create it // we double check before each usage to verify the delegates function pointer +#pragma warning disable CA1416 // This call site is reachable on all platforms. if ((null == CreateCommand) || (method != Marshal.GetFunctionPointerForDelegate(CreateCommand))) +#pragma warning restore CA1416 { CreateCommand = Marshal.GetDelegateForFunctionPointer(method); constr.DangerousIDBCreateCommandCreateCommand = CreateCommand; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs index 4a5d463414f04b..2abacc9285086c 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs @@ -642,7 +642,9 @@ internal unsafe void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServe int result; fixed (char* partitionPtr = partition) { +#pragma warning disable CA1416 // This call site is reachable on all platforms. IntPtr syncAllFunctionPointer = Marshal.GetFunctionPointerForDelegate(syncAllCallback); +#pragma warning restore CA1416 result = dsReplicaSyncAllW(handle, partitionPtr, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, &pErrors); GC.KeepAlive(syncAllCallback); } diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index df4306da1b7ec8..fd235099d6a201 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -18,6 +18,7 @@ internal static partial class ComponentActivator [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("tvos")] @@ -56,6 +57,7 @@ private static string MarshalToString(IntPtr arg, string argName) [RequiresUnreferencedCode(TrimIncompatibleWarningMessage, Url = "https://aka.ms/dotnet-illink/nativehost")] [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("tvos")] @@ -106,6 +108,7 @@ public static unsafe int LoadAssemblyAndGetFunctionPointer(IntPtr assemblyPathNa [RequiresDynamicCode(NativeAOTIncompatibleWarningMessage)] [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("tvos")] @@ -139,6 +142,7 @@ public static int LoadAssembly(IntPtr assemblyPathNative, IntPtr loadContext, In [RequiresUnreferencedCode(TrimIncompatibleWarningMessage, Url = "https://aka.ms/dotnet-illink/nativehost")] [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("tvos")] @@ -281,6 +285,7 @@ public static unsafe int GetFunctionPointer(IntPtr typeNameNative, [RequiresUnreferencedCode(TrimIncompatibleWarningMessage, Url = "https://aka.ms/dotnet-illink/nativehost")] [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] private static IsolatedComponentLoadContext GetIsolatedComponentLoadContext(string assemblyPath) @@ -350,7 +355,9 @@ private static IntPtr InternalGetFunctionPointer(AssemblyLoadContext alc, { Delegate d = Delegate.CreateDelegate(delegateType, type, methodName); +#pragma warning disable CA1416 // This call site is reachable on all platforms. functionPtr = Marshal.GetFunctionPointerForDelegate(d); +#pragma warning restore CA1416 lock (s_delegates) { diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/IsolatedComponentLoadContext.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/IsolatedComponentLoadContext.cs index 6dcc8f661d9dc4..01d495e0f6848c 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/IsolatedComponentLoadContext.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/IsolatedComponentLoadContext.cs @@ -16,6 +16,7 @@ namespace Internal.Runtime.InteropServices /// [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("maccatalyst")] [UnsupportedOSPlatform("tvos")] diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index be6e089fc7b9bb..8716d199fc7df1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -1198,15 +1198,21 @@ public static TDelegate GetDelegateForFunctionPointer(IntPtr ptr) [RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate overload instead.")] [EditorBrowsable(EditorBrowsableState.Never)] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")] public static IntPtr GetFunctionPointerForDelegate(Delegate d) { ArgumentNullException.ThrowIfNull(d); + if (OperatingSystem.IsWasi() || OperatingSystem.IsBrowser()) throw new PlatformNotSupportedException(SR.PlatformNotSupported_DynamicEntrypoint); + return GetFunctionPointerForDelegateInternal(d); } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:AotUnfriendlyApi", Justification = "AOT compilers can see the T.")] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")] public static IntPtr GetFunctionPointerForDelegate(TDelegate d) where TDelegate : notnull { return GetFunctionPointerForDelegate((Delegate)(object)d); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.PlatformNotSupported.cs index 5f0597bf337bed..53d396c76ca834 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.PlatformNotSupported.cs @@ -8,6 +8,7 @@ namespace System.Runtime.Loader { [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] public sealed class AssemblyDependencyResolver diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs index e4e6f2269a070e..fe9ab708457447 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs @@ -12,6 +12,7 @@ namespace System.Runtime.Loader { [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] + [UnsupportedOSPlatform("wasi")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] public sealed class AssemblyDependencyResolver @@ -47,7 +48,9 @@ public AssemblyDependencyResolver(string componentAssemblyPath) // to the writer specified. Have to store the previous writer to set it back once this is done. var errorWriter = new Interop.HostPolicy.corehost_error_writer_fn(message => errorMessage.AppendLine(Marshal.PtrToStringAuto(message))); +#pragma warning disable CA1416 // This call site is reachable on all platforms. IntPtr errorWriterPtr = Marshal.GetFunctionPointerForDelegate(errorWriter); +#pragma warning restore CA1416 IntPtr previousErrorWriterPtr = Interop.HostPolicy.corehost_set_error_writer(errorWriterPtr); try diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index 593a42224208d8..2ced5d000838cd 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -1072,7 +1072,11 @@ public static void FreeHGlobal(System.IntPtr hglobal) { } public static System.IntPtr GetExceptionPointers() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate overload instead.")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")] public static System.IntPtr GetFunctionPointerForDelegate(System.Delegate d) { throw null; } + [System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")] + [System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")] public static System.IntPtr GetFunctionPointerForDelegate(TDelegate d) where TDelegate : notnull { throw null; } [System.Diagnostics.CodeAnalysis.RequiresAssemblyFiles("Windows only assigns HINSTANCE to assemblies loaded from disk. This API will return -1 for modules without a file on disk.")] public static System.IntPtr GetHINSTANCE(System.Reflection.Module m) { throw null; } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs index f0745272af906c..5e70e5801e57d5 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs @@ -11,7 +11,7 @@ namespace System.Runtime.InteropServices.Tests { - [ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)] + [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public class GetDelegateForFunctionPointerTests { [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetFunctionPointerForDelegateTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetFunctionPointerForDelegateTests.cs index 79c3adb3c91abc..750cefd167fa5b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetFunctionPointerForDelegateTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetFunctionPointerForDelegateTests.cs @@ -10,8 +10,7 @@ namespace System.Runtime.InteropServices.Tests { public class GetFunctionPointerForDelegateTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))] public void GetFunctionPointerForDelegate_NormalDelegateNonGeneric_ReturnsExpected() { MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static); @@ -23,8 +22,7 @@ public void GetFunctionPointerForDelegate_NormalDelegateNonGeneric_ReturnsExpect Assert.Equal(pointer1, pointer2); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))] public void GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsExpected() { MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static); @@ -40,8 +38,7 @@ public void GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsEx Assert.Equal(pointer1, pointer2); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))] public void GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected() { MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static); @@ -53,8 +50,7 @@ public void GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected( Assert.Equal(pointer1, pointer2); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))] public void GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected() { MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static); diff --git a/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs b/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs index a272e40c33db39..db5115c1fb2801 100644 --- a/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs +++ b/src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs @@ -45,6 +45,7 @@ namespace System.Runtime.Loader { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("wasi")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public sealed partial class AssemblyDependencyResolver diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs index fa6be7f42e7403..bcb9005ae08a4e 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs @@ -697,11 +697,13 @@ private void Initialize(bool multipleServices) private SERVICE_TABLE_ENTRY GetEntry() { _nameFrozen = true; +#pragma warning disable CA1416 // This call site is reachable on all platforms. return new SERVICE_TABLE_ENTRY() { callback = Marshal.GetFunctionPointerForDelegate(_mainCallback!), name = Marshal.StringToHGlobalUni(_serviceName) }; +#pragma warning restore CA1416 } private int ServiceCommandCallbackEx(int command, int eventType, IntPtr eventData, IntPtr eventContext) diff --git a/src/mono/browser/runtime/runtime.c b/src/mono/browser/runtime/runtime.c index 49dae17f50228f..e19a212c34a4de 100644 --- a/src/mono/browser/runtime/runtime.c +++ b/src/mono/browser/runtime/runtime.c @@ -197,6 +197,8 @@ init_icall_table (void) static void* get_native_to_interp (MonoMethod *method, void *extra_arg) { + assert (method); + void *addr = NULL; MONO_ENTER_GC_UNSAFE; MonoClass *klass = mono_method_get_class (method); diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index f3cc76774ce8ea..96306eb3bc39aa 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -3520,6 +3520,14 @@ interp_create_method_pointer (MonoMethod *method, gboolean compile, MonoError *e if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) { WrapperInfo *info = mono_marshal_get_wrapper_info (method); MonoMethod *orig_method = info->d.native_to_managed.method; + if (!orig_method) { + char *s = mono_method_get_full_name (method); + char *msg = g_strdup_printf ("No native to managed transition for method '%s', missing [UnmanagedCallersOnly] attribute.", s); + mono_error_set_platform_not_supported (error, msg); + g_free (s); + g_free (msg); + return NULL; + } /* * These are called from native code. Ask the host app for a trampoline.