Repository navigation
Open
Description
Description
When running tests with --coverage flag using Microsoft Testing Platform (MTP) on .NET 10 with NUnit, tests pass successfully and the coverage file is generated, but the process crashes during async cleanup with BadImageFormatException: Index not found.
Environment
- OS: Ubuntu Linux (GitHub Actions runner) and macOS ARM64
- .NET SDK: 10.0.101
- Test Framework: NUnit 4.4.0
- Test Adapter: NUnit3TestAdapter 6.1.0
- MTP Packages:
- Microsoft.Testing.Platform.MSBuild 2.0.2
- Microsoft.Testing.Extensions.Telemetry 2.0.2
- Microsoft.Testing.Extensions.CodeCoverage 18.3.1 and 18.3.2 (both crash)
Reproduction
- Create a .NET 10 test project with NUnit and MTP enabled
- Configure
global.jsonwith"test": { "runner": "Microsoft.Testing.Platform" } - Run:
dotnet test --coverage --coverage-output-format cobertura
Expected Behavior
Tests complete and process exits with code 0.
Actual Behavior
Tests pass (762 passed in our case), coverage file IS generated, but then:
NUnit Adapter 6.1.0.0: Test execution complete
Error output: Unhandled exception. System.BadImageFormatException: Index not found. (0x80131124)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__124_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
In process file artifacts produced:
- /path/to/TestResults/<guid>.cobertura.xml
Test run summary: Failed!
error: 1
total: 764
failed: 0
succeeded: 762
skipped: 2
Exit code: 134 (SIGABRT)
Workaround
Running without --coverage flag works fine:
dotnet test # Works, exit code 0
dotnet test --coverage # Crashes with exit code 134Notes
- The crash occurs AFTER tests complete and coverage file is written
- The exception is in async cleanup/finalization phase
- Tested with both CodeCoverage 18.3.1 and 18.3.2 - same crash
dotnet-coverage collectCLI tool also shows "Profiler was not initialized"
Reacted by David Osolkowski and Alex Martossy
Metadata
Metadata
Assignees
Labels
No labels
Activity
Fix MTP code coverage crash on .NET 10
Fix code coverage for build-standards update
Bump build-standards from `30b15cf` to `4ff88bc` (#57)
Fix CI coverage for Microsoft Testing Platform
jas88 commentedon Jan 18, 2026
Additional Workaround: Use Dynamic Instrumentation
We found that the static instrumentation causes this crash, but dynamic instrumentation works without issues.
Solution
Create a
coverage.settingsfile:Then run with:
dotnet test -- --coverage --coverage-output-format cobertura --coverage-settings coverage.settingsImportant Notes
Dynamic instrumentation platform support: Only works on Windows (x86/x64/Arm64), Linux (x64), and macOS (x64). Not supported on macOS arm64 - will produce empty coverage on Apple Silicon.
Microsoft Testing Platform users: The
--coverage*options must come after--separator since they're MTP extension options, notdotnet testoptions.Disabling restore alone doesn't work: Setting
EnableStaticManagedInstrumentationRestore=falsedoes not prevent the crash - the corruption happens during instrumentation, not restore. You must disable static instrumentation entirely.Why This Works
The crash occurs because static instrumentation corrupts async state machine metadata. The
BadImageFormatExceptionhappens when .NET runtime accesses this corrupted metadata during cleanup. Dynamic instrumentation doesn't modify the binaries, avoiding this issue entirely.Tested with .NET 10, NUnit 4.x, Microsoft.Testing.Extensions.CodeCoverage 18.3.x on Linux x64.
chore(deps): bump build-standards from `26cc6e1` to `c562f19` (#350)
fhnaseer commentedon Jan 19, 2026
James A Sutherland (@jas88) Thanks for the detailed analysis and workaround. Can you please try to use
dotnet runcommand instead ofdotnet test(with default settings) and see if it fixes the issue?jas88 commentedon Jan 19, 2026
Tested
dotnet runinstead ofdotnet testas suggested in the comment.Test setup: TypeGuesser project on ubuntu-latest with .NET 10, using Microsoft Testing Platform + NUnit.
Result: Still fails with exit code 134, but with additional named pipe errors:
Command used:
No
--coverage-settingswas passed, so this is using default static instrumentation.CI run: https://github.com/jas88/TypeGuesser/actions/runs/21146014542
The dynamic instrumentation workaround (
EnableStaticManagedInstrumentation=false) continues to work with bothdotnet testanddotnet run.dosolkowski-work commentedon Feb 5, 2026
I've hit this error as well, and sometimes it comes with a different exception:
This is also on the latest versions, .NET SDK 10.0.102 and Microsoft.Testing.Extensions.CodeCoverage 18.4.1, and using TUnit 1.12.139 instead of NUnit, so the problem isn't specific to NUnit.
In my case, it only happened with
IncludeTestAssemblyturned on and only on Linux. On Windows, or withIncludeTestAssemblyturned off, there was no issue. The workaround of using dynamic instrumentation instead of static also makes the error go away.rosanch commentedon Apr 6, 2026
The workaround above does not work for our team. However, our stack trace (differs from OP):
Unhandled exception. System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(...)
at System.IO.Pipes.NamedPipeServerStream.WaitForConnectionAsync(...)
at Microsoft.Testing.Platform.IPC.NamedPipeServer.WaitConnectionAsync(CancellationToken)
at Microsoft.Testing.Platform.Hosts.TestHostControllersTestHost.InternalRunAsync(CancellationToken)
Key differences from other reports:
Our workaround: --max-parallel-test-modules 1. Speed impact is from 3 minutes to over 15 min.
This appears to be a separate issue from the static instrumentation corruption reported by others. Our crash is in the MTP IPC layer (NamedPipeServer.WaitConnectionAsync), not in the instrumented code. It manifests as a race condition where the controller host's named pipe connection times out before the child test host (with coverage profiler) is ready to connect.
Packages:
xunit.v3.mtp-v2xunit.v3.assertxunit.v3.extensibility.corexunit.v3.runner.consoleMicrosoft.Testing.Extensions.CodeCoveragerosanch commentedon Apr 6, 2026
Update on my previous comment
WORKAROUND
Found a workaround by increasing MTP named pipe connection timeout on Linux
$env:TESTINGPLATFORM_DEFAULT_HANG_TIMEOUT = "300s"
--max-parallel-test-modules 4
Note: Bare numbers are parsed as milliseconds by MTP's TimeSpanParser. Always use a suffix: "300s", "5m", etc.
Why it only affects Linux with --coverage: Without coverage, no TestHostControllers are registered and there's no out-of-process pipe handshake. On Windows, named pipes use async kernel objects with native multi-instance support; on Linux, they're file-based Unix domain sockets created without PipeOptions.Asynchronous, making them slower under contention.
Unskip IncludeTestAssembly=true cases via dynamic instrumentation wor…
Revert dynamic-instrumentation workaround; keep IncludeTestAssembly=t…
[DO NOT MERGE] Temporarily unskip IncludeTestAssembly=true cases to v…
fix(samples): Aspire sample uses dynamic coverage instrumentation