Skip to content

Commit a2bbad7

Browse files
[HotReloadAgent] Handle unsupported platform for PosixSignalRegistration (#52466)
If running on Android, for example, you can get the following exception: 01-14 10:46:37.635 28537 28537 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 01-14 10:46:37.635 28537 28537 F mono-rt : ---> System.PlatformNotSupportedException: Operation is not supported on this platform. 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Runtime.InteropServices.PosixSignalRegistration.Register(PosixSignal signal, Action`1 handler) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Runtime.InteropServices.PosixSignalRegistration.Create(PosixSignal signal, Action`1 handler) 01-14 10:46:37.635 28537 28537 F mono-rt : at StartupHook.RegisterSignalHandlers() 01-14 10:46:37.635 28537 28537 F mono-rt : at StartupHook.InitializeWithHttp(String processDir) 01-14 10:46:37.635 28537 28537 F mono-rt : at StartupHook.Initialize() 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) 01-14 10:46:37.635 28537 28537 F mono-rt : --- End of inner exception stack trace --- 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook) 01-14 10:46:37.635 28537 28537 F mono-rt : at System.StartupHookProvider.ProcessStartupHooks(String diagnosticStartupHooks) Just like in 79e5fa6, `PosixSignalRegistration` APIs are decorated with: [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] public static PosixSignalRegistration Create(PosixSignal signal, Action<PosixSignalContext> handler); This is used for handling Ctrl+C, for example, which we'll likely implement a different way for mobile platforms. For now, let's not run the `PlatformNotSupportedException`-throwing code on unsupported platforms.
1 parent 6cadd91 commit a2bbad7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal sealed class StartupHook
2626
&& !OperatingSystem.IsIOS()
2727
&& !OperatingSystem.IsTvOS()
2828
&& !OperatingSystem.IsBrowser();
29+
private static readonly bool s_supportsPosixSignals = s_supportsConsoleColor;
2930

3031
#if NET10_0_OR_GREATER
3132
private static PosixSignalRegistration? s_signalRegistration;
@@ -125,7 +126,7 @@ private static void RegisterSignalHandlers()
125126
[DllImport("kernel32.dll", SetLastError = true)]
126127
static extern bool SetConsoleCtrlHandler(Delegate? handler, bool add);
127128
}
128-
else
129+
else if (s_supportsPosixSignals)
129130
{
130131
#if NET10_0_OR_GREATER
131132
// Register a handler for SIGTERM to allow graceful shutdown of the application on Unix.

0 commit comments

Comments
 (0)