Skip to content

KeyNotFoundException if test session cancelled #6972

Closed as duplicate
Closed as duplicate

Description

Describe the bug

I'm not sure exactly how early in the process the test session needs to be cancelled, but when running some tests with MTP v2 and trying to cancel with CTRL+C, I got the following error logged to the terminal:

System.Collections.Generic.KeyNotFoundException: The given key 'c35ce0e4fb41425dadd0e345f4b0c534' was not present in the dictionary.
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey key)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at Microsoft.DotNet.Cli.Commands.Test.Terminal.TerminalTestReporter.AssemblyRunCompleted(String executionId, Int32 exitCode, String outputData, String errorData)
   at Microsoft.DotNet.Cli.Commands.Test.TestApplicationHandler.OnTestProcessExited(Int32 exitCode, String outputData, String errorData)
   at Microsoft.DotNet.Cli.Commands.Test.TestApplication.RunAsync()
   at Microsoft.DotNet.Cli.Commands.Test.TestApplication.RunAsync()
   at Microsoft.DotNet.Cli.Commands.Test.TestApplicationActionQueue.Read(BuildOptions buildOptions, TestOptions testOptions, TerminalTestReporter output, Action`1 onHelpRequested)

My guess would be that the runner knows a session ID, but the cancel took affect before it was actually created, so whatever it's looking for isn't in the dictionary.

Steps To Reproduce

Cancel dotnet test with CTRL+C early in the test session when MTP v2 is in use.

Expected behavior

The process exits without any errors.

Actual behavior

An exception is thrown.

Additional context

None.

Activity

  1. Youssef1313 commented on Nov 22, 2025

    @Youssef1313
    Member

    Duplicate of dotnet/sdk#51608

  2. Youssef1313 commented on Nov 22, 2025

    @Youssef1313
    Member

    Martin Costello (@martincostello) Just to double check. Was this run simply a dotnet test? Or did it involve out-of-proc extensions, like hangdump or other out-of-proc extension?

  3. martincostello commented on Nov 22, 2025

    @martincostello
    ContributorAuthor

    My end-state was with hang dumps being enabled, but it not sure at what point during iterating I was at when that happened.

  4. Youssef1313 commented on Nov 22, 2025

    @Youssef1313
    Member

    My end-state was with hang dumps being enabled

    That aligns with my expectation of the bug as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions