Skip to content

[fix] Improve error message when testhost cannot be found#16053

Open
nohwnd wants to merge 1 commit into
mainfrom
fix/issue-15112-8e2838381f3266fc
Open

[fix] Improve error message when testhost cannot be found#16053
nohwnd wants to merge 1 commit into
mainfrom
fix/issue-15112-8e2838381f3266fc

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented May 22, 2026

Summary

🤖 This is an automated fix generated by the Issue Repro Triage agent.

Fixes #15112

Root Cause

When DotnetTestHostManager could not find testhost.dll anywhere on disk, it threw a TestPlatformException with the message "Could not find testhost". This message provided no context about:

  • Which test source was being processed
  • Which directories were searched
  • What steps the user could take to resolve it

This was reported when a NuGet package setup prevented testhost.exe from being copied to the output bin folder. The vague message made self-diagnosis impossible.

Fix

Replace the generic message with one that includes:

  1. The test source path — so the user knows which project triggered the failure
  2. The output directory — so the user can verify what is/isn't there
  3. Actionable hints — check Microsoft.NET.Test.Sdk NuGet reference, ensure the project is built, and verify the target framework

Before:

Could not find testhost

After:

Could not find testhost for test source '/path/to/my.test.dll'.

Verify that:
  - The test project references the 'Microsoft.NET.Test.Sdk' NuGet package.
  - The project has been built and the output is in '/path/to/'.
  - The project's target framework matches the installed .NET runtime.

Testing

Added unit test GetTestHostProcessStartInfoShouldIncludeSourcePathInExceptionMessageWhenTesthostNotFound that verifies the exception message contains both the source path and directory when testhost cannot be found.

🔍 Triaged by Issue Repro Triage & Auto-Fix 🔍

When the test platform cannot find testhost.dll, the previous error
message 'Could not find testhost' was too vague to diagnose.

The new message includes:
- The test source path that was being processed
- The directory that was searched
- Actionable suggestions to check Microsoft.NET.Test.Sdk reference
  and ensure the project has been built

Fixes #15112

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 22, 2026 13:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves diagnosability when DotnetTestHostManager cannot locate testhost.dll by replacing a generic exception message with a localized, actionable message that includes the failing test source and its output directory.

Changes:

  • Add a new localized resource (CouldNotFindTesthost) containing a more detailed “testhost not found” error message with troubleshooting hints.
  • Update DotnetTestHostManager.GetTestHostProcessStartInfo to throw TestPlatformException using the new resource, including source path and directory.
  • Add a unit test covering the new exception message content, and propagate the new resource into all related .xlf files.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs Adds a unit test asserting the new exception message includes context.
src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs Uses the new localized resource to throw a more informative exception when testhost cannot be found.
src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx Introduces the CouldNotFindTesthost resource string and comment.
src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs Adds the strongly-typed accessor for the new resource.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf Adds the new resource entry for localization workflow.
src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf Adds the new resource entry for localization workflow.
Files not reviewed (1)
  • src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs: Language not supported


var exception = Assert.ThrowsExactly<TestPlatformException>(action);
Assert.Contains(sourcePath, exception.Message);
Assert.Contains(sourceDirectory, exception.Message);
Copy link
Copy Markdown
Member Author

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Dimensions activated: Error Reporting & Diagnostic Clarity · Process Architecture & Host Resolution

The change is correct and well-implemented:

  • sourcePath and sourceDirectory are derived from sources.Single() at method entry (lines 268–270), so they are guaranteed to be set before the throw site at line 462 — no null-path risk.
  • All 14 XLF localization files are updated with state="new" entries as required.
  • The unit test GetTestHostProcessStartInfoShouldIncludeSourcePathInExceptionMessageWhenTesthostNotFound correctly verifies both paths appear in the message, and Assert.Contains(needle, haystack) order is correct.
  • No public API surface changes, no IPC wire format impact, no binding redirect concerns.

🧠 Reviewed by Expert Code Reviewer

🧠 Reviewed by Expert Code Reviewer 🧠

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error messaging when failing to run tests

2 participants