BadImageFormatException crash after tests complete with --coverage on .NET 10 + NUnit

Open
#203 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp

Research direction

Start by reproducing the failure with the .NET 10 project described in global.json using dotnet test --coverage --coverage-output-format cobertura, then compare it with dotnet test without coverage. Trace the Microsoft Testing Platform and CodeCoverage cleanup path, including the dotnet-coverage collect entry point. Done means coverage is generated, cleanup completes without BadImageFormatException, and the process exits with code 0.

Written by the indexing model from the issue text.

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

  1. Create a .NET 10 test project with NUnit and MTP enabled
  2. Configure global.json with "test": { "runner": "Microsoft.Testing.Platform" }
  3. 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 134

Notes

  • 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 collect CLI tool also shows "Profiler was not initialized"
Dominant language
C#
Stars
125
Forks
17
Avg merge
1h 17m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/codecoverage

All issues in microsoft/codecoverage

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.