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
dotnet test for MTP throws hard-to-interpret KeyNotFoundException #51608
So far I saw it only once, but I think it's worth investigating:
The following exception occurred when running the test module with RunCommand '/Users/runner/work/1/s/artifacts/bin/Microsoft.Testing.Extensions.UnitTests/Debug/net9.0/Microsoft.Testing.Extensions.UnitTests' and RunArguments ' --diagnostic --diagnostic-output-directory /Users/runner/work/1/s/artifacts/log/Debug --diagnostic-file-prefix Microsoft.Testing.Extensions.UnitTests_net9.0_Debug_x64 --diagnostic-verbosity trace --crashdump --hangdump --hangdump-timeout 15m --report-azdo --coverage --coverage-settings /Users/runner/work/1/s/test/coverage.config --coverage-output Microsoft.Testing.Extensions.UnitTests_net9.0_Debug_x64.coverage --report-trx --report-trx-filename Microsoft.Testing.Extensions.UnitTests_net9.0_x64.trx --results-directory /Users/runner/work/1/s/artifacts/TestResults/Debug/':
System.Collections.Generic.KeyNotFoundException: The given key 'ba98a3b7d1b0470a866ea837070091b8' 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)
In addition, this exception was just buried somewhere in the middle of the output and wasn't surfaced towards the end of the output.
We started a test host controller, the test host controller failed for some reason and exited. In that case, we got a handshake from the controller, but we never called AssemblyRunStarted because the testhost didn't start. Then we called AssemblyRunCompleted, but the key won't be found in the dictionary.
What is missing here:
Are we burying the reason why test host controller failed?
The error should probably surface in a better way.
changed the title [-]`dotnet test` for MTP crashed randomly accessing a key in dictionary that doesn't exist[/-][+]`dotnet test` for MTP throws hard-to-interpret KeyNotFoundException[/+]on Nov 7, 2025
The following exception occurred when running the test module with RunCommand '/home/runner/work/MyTests' and RunArguments ' ':
System.Collections.Generic.KeyNotFoundException: The given key '90beda4603ef4b3faaa78373d263f779' 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)
I have tried enabling diagnostic logs, but I don't really get any more useful details from those. Is there anything I can do to see what is causing the issue so that I might fix it? Strangely enough I'm only getting this issue on my test suite for one of the test projects, and only when running on GitHub Actions: On WSL locally it runs just find. I'm kind of at a loss as to what to do, to further debug the issue.
My projects were organized like this. Note that this is the actual directory structure, and not the solution structure, which doesn't necessarily follow the actual underlying directory structure:
Now I suddenly had three test projects with the error: Test project 6, 1, 5. Then I just flatly organized all projects under src/, and suddenly all test projects run successfully.
The solution folders did not seem to affect the issue.
@jackmtpt@AndreasPetersen The KeyNotFoundException here is just a sign of something else failing. Without providing more information/repro for your specific cases, it will be hard to say exactly what's wrong.
Activity
Youssef1313 commentedon Nov 7, 2025
I have a theory here.
We started a test host controller, the test host controller failed for some reason and exited. In that case, we got a handshake from the controller, but we never called
AssemblyRunStartedbecause the testhost didn't start. Then we calledAssemblyRunCompleted, but the key won't be found in the dictionary.What is missing here:
[-]`dotnet test` for MTP crashed randomly accessing a key in dictionary that doesn't exist[/-][+]`dotnet test` for MTP throws hard-to-interpret KeyNotFoundException[/+]dotnet testMicrosoft.Testing.Platform experience #45927Youssef1313 commentedon Nov 22, 2025
There are additional details in microsoft/testfx#6972.
AndreasPetersen commentedon Dec 29, 2025
I have a test suite where I get this error
I have tried enabling diagnostic logs, but I don't really get any more useful details from those. Is there anything I can do to see what is causing the issue so that I might fix it? Strangely enough I'm only getting this issue on my test suite for one of the test projects, and only when running on GitHub Actions: On WSL locally it runs just find. I'm kind of at a loss as to what to do, to further debug the issue.
AndreasPetersen commentedon Dec 30, 2025
Okay I managed to find a workaround for my issue.
My projects were organized like this. Note that this is the actual directory structure, and not the solution structure, which doesn't necessarily follow the actual underlying directory structure:
It was only Test project 6 that was failing. I then reorganized my solution to:
Now I suddenly had three test projects with the error: Test project 6, 1, 5. Then I just flatly organized all projects under src/, and suddenly all test projects run successfully.
The solution folders did not seem to affect the issue.
jackmtpt commentedon Jan 6, 2026
I've also started running into this on a multi-targeted test project. The .NET 10 assembly runs fine, but the .NET 8 one does not.
Youssef1313 commentedon Jan 6, 2026
@jackmtpt @AndreasPetersen The KeyNotFoundException here is just a sign of something else failing. Without providing more information/repro for your specific cases, it will be hard to say exactly what's wrong.
jackmtpt commentedon Jan 6, 2026
looks like the test assembly died for whatever reason, poking about in the crash dump for it now...
Youssef1313 commentedon Jan 16, 2026
Fixed in #52308, but we still need to write a test for it. The PR was merged without any tests.
Fix KeyNotFoundException in TerminalTestReporter.AssemblyRunCompleted (…
Fix KeyNotFoundException in TerminalTestReporter.AssemblyRunCompleted (…
Improve handshake failure visibility in dotnet test
Escalate run verdict to 'Failed!' on handshake failure (dotnet/sdk#51608
Reconcile dotnet.Tests with the [Embedded] Internal.DotnetTest packag…