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

Created on 8 Oct 2019  Â·  9Comments  Â·  Source: microsoft/vstest

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'

Most helpful comment

@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 https://github.com/microsoft/vstest/pull/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*.

All 9 comments

@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 https://github.com/microsoft/vstest/pull/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*.

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

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

Have you tried updating to the newest version?

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"

Yes I updated to newest version. It is working fine

On Tue, 4 Aug, 2020, 7:33 PM Rob Smitha, notifications@github.com wrote:

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

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vstest/issues/2218#issuecomment-668615686,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AGQE5CS633SCBWUCREZX7CTR7AIL7ANCNFSM4I6RUDQQ
.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings