[fix] Improve error message when testhost cannot be found#16053
Open
nohwnd wants to merge 1 commit into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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.GetTestHostProcessStartInfoto throwTestPlatformExceptionusing 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
.xlffiles.
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); |
nohwnd
commented
May 22, 2026
Member
Author
nohwnd
left a comment
There was a problem hiding this comment.
Code Review
Dimensions activated: Error Reporting & Diagnostic Clarity · Process Architecture & Host Resolution
The change is correct and well-implemented:
sourcePathandsourceDirectoryare derived fromsources.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
GetTestHostProcessStartInfoShouldIncludeSourcePathInExceptionMessageWhenTesthostNotFoundcorrectly verifies both paths appear in the message, andAssert.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 🧠
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
🤖 This is an automated fix generated by the Issue Repro Triage agent.
Fixes #15112
Root Cause
When
DotnetTestHostManagercould not findtesthost.dllanywhere on disk, it threw aTestPlatformExceptionwith the message"Could not find testhost". This message provided no context about:This was reported when a NuGet package setup prevented
testhost.exefrom being copied to the output bin folder. The vague message made self-diagnosis impossible.Fix
Replace the generic message with one that includes:
Microsoft.NET.Test.SdkNuGet reference, ensure the project is built, and verify the target frameworkBefore:
After:
Testing
Added unit test
GetTestHostProcessStartInfoShouldIncludeSourcePathInExceptionMessageWhenTesthostNotFoundthat verifies the exception message contains both the source path and directory when testhost cannot be found.