Failed Tests in DevOps Pipeline due to "could not find testhost"

Copper Contributor

Hi ,

 

I am facing the below issue while deploying my Azure Functions. There are tests written in the pipeline which are failing with the below error. Any suggestions?

 

##[error]Could not find testhost
##[error]Testhost process for source(s) 'D:\a\1\s\projecttest\bin\Debug\net6.0\testhost.dll' exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
##[error]Failed to run as a self-contained app.
##[error] - The application was run as a self-contained app because 'D:\a\1\s\projecttest\bin\Debug\net6.0\testhost.runtimeconfig.json' was not found.
##[error] - If this should be a framework-dependent app, add the 'D:\a\1\s\projecttest\bin\Debug\net6.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
##[error]. Please check the diagnostic logs for more information.

5 Replies

@umashankarsharma 

This error message indicates that the test host required to run your tests is not found.

Here are some possible solutions to this issue:

  1. Verify .NET Core version: Make sure that you have the correct version of .NET Core installed on your build machine. You can check the version by running the command "dotnet --version". If you have the incorrect version, you can install the correct version from the official .NET website.

  2. Check the runtimeconfig.json file: Ensure that the testhost.runtimeconfig.json file exists in the expected location and that it specifies the correct .NET Core runtime version. If the file is missing, you can create it using the "dotnet new runtimeconfig" command.

  3. Reinstall .NET Core runtime: If the problem persists, you can try reinstalling the .NET Core runtime on your build machine. You can download the latest version from the official .NET website and install it on your machine.

  4. Update NuGet packages: Make sure that you have updated the NuGet packages in your solution to the latest version. Outdated packages can cause compatibility issues and result in this error.

  5. Check the test project's dependencies: Ensure that all of the required dependencies for the test project are installed and referenced correctly. Check the project's .csproj file to make sure that all required packages are included in the project.

  6. Delete bin and obj folders: Sometimes, deleting the bin and obj folders from your solution and rebuilding it can resolve the issue.

Try these solutions one by one until the error is resolved. If the problem still persists, you can check the diagnostic logs for more information and share it with the support team for further assistance.

@muhammadimran-dev :xd:

 

Guess I used ChatGPT and looked at this result. I still think there is a way to go until it gives concrete answer rather then a generic response.

 

Thank you anyways.

@muhammadimran-dev 


@muhammadimran-dev wrote:
  1.  

  2. Check the runtimeconfig.json file: Ensure that the testhost.runtimeconfig.json file exists in the expected location and that it specifies the correct .NET Core runtime version. If the file is missing, you can create it using the "dotnet new runtimeconfig" command.

 How do I run this command in Azure devops? Thanks

@umashankarsharma hi, not sure if it's going to help or it's too late, but add to the unit tests Nuget Package called Microsoft.NET.Test.Sdk (mine is version 17.7.0), I had that exact problem in my local machine and after an hour of banging on the head at the desk and adding that library worked nicely. I will try to update this post if it worked on my pipeline setup.

@ppit89 Hi, thank you so much for your answer. You literally saved my day. Adding Microsoft.NET.Test.Sdk Nuget package in each test project solved the issue