Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Pipelines VSTest task fails after Microsoft.NET.Test.Sdk is updated from 16.2 to 16.3 #2218

Closed
nkristek opened this issue Oct 8, 2019 · 9 comments

Comments

@nkristek
Copy link

nkristek commented Oct 8, 2019

Description

Starting with the most recent commit to my project Stein the CI build provided by Azure Pipelines fails.
The build in question: https://dev.azure.com/nkristek/Stein/_build/results?buildId=148

Specifically the VSTest task fails with the error:

##[error]Testhost process exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'd:\a\1\s\test\Stein.ViewModels.Tests\bin\Release\netcoreapp2.1\'.
##[error]Failed to run as a self-contained app. If this should be a framework-dependent app, add the d:\a\1\s\test\Stein.ViewModels.Tests\bin\Release\netcoreapp2.1\testhost.runtimeconfig.json file specifying the appropriate framework.

Previously everything ran fine, this commit updated dependencies. Specifically the Microsoft.NET.Test.Sdk was updated from 16.2 to 16.3.
I reran the previous commit with success: https://dev.azure.com/nkristek/Stein/_build/results?buildId=149
This seems to indicate that the new version of Microsoft.NET.Test.Sdk produces this error.

Steps to reproduce

Run Azure Pipelines build with the following repository and settings:
Repository: https://github.com/nkristek/Stein
Configuration: https://github.com/nkristek/Stein/blob/master/azure-pipelines.yml

Expected behavior

The VSTest task succeeds.

Actual behavior

The VSTest task fails with the error:

##[error]Testhost process exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'd:\a\1\s\test\Stein.ViewModels.Tests\bin\Release\netcoreapp2.1\'.
##[error]Failed to run as a self-contained app. If this should be a framework-dependent app, add the d:\a\1\s\test\Stein.ViewModels.Tests\bin\Release\netcoreapp2.1\testhost.runtimeconfig.json file specifying the appropriate framework.

Diagnostic logs

Please share test platform diagnostics logs. Instructions to collect logs are here.
The logs may contain test assembly paths, kindly review and mask those before sharing.

Environment

Configuration: https://github.com/nkristek/Stein/blob/master/azure-pipelines.yml:

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  
strategy:
  maxParallel: 2
  matrix:
    x86:
      buildPlatform: 'x86'
      buildConfiguration: 'Release'
    x64:
      buildPlatform: 'x64'
      buildConfiguration: 'Release'

steps:
- task: DotNetCoreInstaller@0
  displayName: 'Install .NET Core 2.1'
  inputs:
    version: '2.1.300'

- task: NuGetToolInstaller@1
  displayName: 'Install NuGet'

- task: NuGetCommand@2
  displayName: 'Restore NuGet packages'
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  displayName: 'Build'
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true

- task: VSTest@2
  displayName: 'Test'
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    codeCoverageEnabled: true
    runSettingsFile: '$(Build.SourcesDirectory)\test\test.runsettings'
@mayankbansal018
Copy link
Contributor

@nkristek we have identified this issue, & it's happening because in the latest SDK we also drop testhost.dll along with the test assembly. Now since your test filter says to pick any test..dll we also try to run test for testhost.dll which is failing abruptly. We apologize for this, & we have already raised a PR to fix this #2206

To help you mitigate it for now we recommend that you either downgrade the SDK version, or modify your test filter to exclude testhost*.

@nkristek
Copy link
Author

nkristek commented Oct 15, 2019

I see similar behavior with another repository Smaragd and GitHub Actions, but the error message is a bit different:
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.

It has the following targets:

  • main project: .NET Standard 2.0
  • unit test project: .NET Core 3.0

Commit
GitHub Actions failed run

GitHub Actions configuration:

name: CI

on: [push, pull_request]

jobs:
  build:
    runs-on: windows-latest  
    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Install .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.0.100'
    - name: Restore
      run: dotnet restore
    - name: Build
      run: dotnet build --no-restore --configuration Release
    - name: Test
      run: dotnet test --no-restore --no-build --configuration Release

Viir added a commit to pine-vm/pine that referenced this issue Oct 30, 2019
Viir added a commit to pine-vm/pine that referenced this issue Oct 30, 2019
The previous version failed on the Github Actions 'windows-2019' environment with following log:
----
##[warning]Startup.cs(104,13): warning CS0618: 'IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.' [D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.WebHost\PersistentProcess.WebHost.csproj]
Startup.cs(28,35): warning ASP0000: Calling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'. [D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.WebHost\PersistentProcess.WebHost.csproj]
##[warning]TestWebHost.cs(724,27): warning CS0649: Field 'TestWebHost.Web_host_propagates_HTTP_headers_Response_Entry.name' is never assigned to, and will always have its default value null [D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.Test\PersistentProcess.Test.csproj]
##[warning]TestWebHost.cs(726,29): warning CS0649: Field 'TestWebHost.Web_host_propagates_HTTP_headers_Response_Entry.values' is never assigned to, and will always have its default value null [D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.Test\PersistentProcess.Test.csproj]
Test run for D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.Test\bin\Debug\netcoreapp3.0\PersistentProcess.Test.dll(.NETCoreApp,Version=v3.0)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.Test\bin\Debug\netcoreapp3.0\].
If this is a framework-dependent application, install the runtime in the default location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
. Please check the diagnostic logs for more information.
Results File: D:\a\elm-fullstack\elm-fullstack\implement\PersistentProcess\PersistentProcess.Test\TestResults\runneradmin_fv-az75_2019-10-30_10_14_51.trx
Test Run Aborted.

##[error]Process completed with exit code 1.
Viir added a commit to pine-vm/pine that referenced this issue Oct 30, 2019
Using Github actions to run the test should enable people to get test results without creating a PR or setting up their own Azure Pipeline.
So far, the Azure Pipelines provide a nicer view of test results, so we keep that for now.
The package version change is to work around an issue seen on the Github actions `windows-2019` environment: microsoft/vstest#2218 (comment)
@nibeditadan
Copy link

I am facing this issue one again, any workarounds please let me know

robert-shattock added a commit to robert-shattock/Pets that referenced this issue Jun 5, 2020
Errors when running tests task related to testhost... following some guidance from here to exclude that dll from being tested itself microsoft/vstest#2218 (comment)
@nkristek
Copy link
Author

nkristek commented Jun 6, 2020

Have you tried updating to the newest version?

@robsmitha
Copy link

robsmitha commented Aug 4, 2020

Removing AnyCPU from my unit test project's csproj fixed this issue for me and my tests are running in the pipeline. I'm thinking this AnyCPU PlatformTarget setting would default to x64 on the build server causing a mismatch in bitness, therefore the library found was mismatched. Hope this helps someone.

netcoreapp2.1
Runtime: 2.1.19
win10-x86
Microsoft.NET.Test.Sdk 16.6.1

EDIT: My error was along the lines of "testhost process exited with error: failed to load the dll from [....hostfxr]. the library hostfxr.dll was found but loading it from [....] failed"

@nibeditadan
Copy link

nibeditadan commented Aug 4, 2020 via email

@M5alil
Copy link

M5alil commented Apr 12, 2021

I am still getting this error when using Microsoft.NET.Test.Sdk 16.9.4
tried to exclude !**\testhost*., but didn't work for me
downgraded to 16.2.0 and worked fine

@msfcolombo
Copy link

@mayankbansal018 I think this should be re-opened. I'm seeing the same issue on 16.10.0.

@adammodlin
Copy link

I'm also getting this issue on 16.9.4 with .NET 6. I'll open a new issue and link it.

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

No branches or pull requests

7 participants