You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MTP mode throws PlatformNotSupportedException on Android: NUnit3TestExecutor subscribes to Console.CancelKeyPress #1549
When NUnit tests run on Microsoft.Testing.Platform inside an Android instrumentation (the dotnet new androidtest template, with builder.AddMSTest(...) swapped for builder.AddNUnit(...)), every run fails before any test executes:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Runtime.InteropServices.PosixSignalRegistration.Register(PosixSignal signal, Action`1 handler)
at System.Runtime.InteropServices.PosixSignalRegistration.Create(PosixSignal signal, Action`1 handler)
at System.Console.add_CancelKeyPress(ConsoleCancelEventHandler value)
at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor..ctor(Boolean isMTP) in .../NUnit3TestExecutor.cs:line 128
at NUnit.VisualStudio.TestAdapter.TestingPlatformAdapter.NUnitBridgedTestFramework.SynchronizedRunTestsAsync(...) in .../NUnitBridgedTestFramework.cs:line 91
at Microsoft.Testing.Extensions.VSTestBridge.SynchronizedSingleSessionVSTestBridgedTestFramework...
The isMTP branch of the constructor (added for #1361) subscribes to Console.CancelKeyPress unconditionally. Console.CancelKeyPress is unsupported on Android (and, per the runtime's [UnsupportedOSPlatform] annotations, iOS, tvOS and browser), so the subscription throws.
NUnit itself works on the device: driving the same test assembly with NUnitTestAssemblyRunner from the instrumentation runs and reports every test. Only the MTP adapter path fails. The stock MSTest version of the template runs under dotnet test --device as expected.
dotnet new androidtest, then in the project: replace the MSTest package with NUnit + NUnit3TestAdapter, EnableMSTestRunner with EnableNUnitRunner, and in TestInstrumentation.csbuilder.AddMSTest(() => [GetType().Assembly]) with builder.AddNUnit(() => [GetType().Assembly])
dotnet test --device <emulator>
Suggested fix
Skip the subscription where it is unsupported, for example:
I checked it on an Android emulator. With 6.3.1, dotnet test --device fails right away with this PlatformNotSupportedException. With the fix, the run gets past the constructor. No test reaches the device yet, though: the NUnit engine fails next (the extension directory scan, then loading the engine and the test assembly). Those are a bigger question than this bug, so I've written them up separately in nunit/nunit-console#1966.
Activity
OsirisTerje commentedon Nov 13, 2026
@zhollis21 Do you want to raise a PR for this ? You have the environment to check it out too, that's an advantage 😄
zhollis21 commentedon Nov 13, 2026
Thanks @OsirisTerje. The PR is up: #1550.
I checked it on an Android emulator. With 6.3.1,
dotnet test --devicefails right away with thisPlatformNotSupportedException. With the fix, the run gets past the constructor. No test reaches the device yet, though: the NUnit engine fails next (the extension directory scan, then loading the engine and the test assembly). Those are a bigger question than this bug, so I've written them up separately in nunit/nunit-console#1966.