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

With NET 5 RC1 x86 SDK installed on x64 OS, run Unit test failed with error: Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found... #13157

Closed
vdanche opened this issue Aug 27, 2020 · 8 comments · Fixed by microsoft/vstest#2571
Assignees

Comments

@vdanche
Copy link
Member

vdanche commented Aug 27, 2020

Machine OS: win10-x64
Repro Steps
Install NET 5 RC1 x86 SDK from https://github.com/dotnet/installer on x64 OS
dotnet new xunint/mstest/nunit in CLI
dotnet build and then dotnet test

Expected result:
Unit test run successfully

Actual result:
run failed with below error:
image
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 [C:\Users\v-danche\today\hahah\bin\Debug\net5.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.

Test Run Aborted.
C:\Program Files (x86)\dotnet\sdk\5.0.100-rc.1.20427.1\Microsoft.TestPlatform.targets(32,5): error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error. [C:\Users\v-danche\today\hahah\hahah.csproj]

Note:
It doesn't repro on x64 SDK.

It only repro on NET 5 RC1 x86.

Dotnet --info:
.NET SDK (reflecting any global.json):
Version: 5.0.100-rc.1.20427.1
Commit: dd2e854

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x86
Base Path: C:\Program Files (x86)\dotnet\sdk\5.0.100-rc.1.20427.1\

Host (useful for support):
Version: 5.0.0-rc.1.20426.10
Commit: bfc00e4e13

.NET SDKs installed:
5.0.100-rc.1.20427.1 [C:\Program Files (x86)\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.0-rc.1.20426.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0-rc.1.20426.10 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.0-rc.1.20426.4 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

@vdanche vdanche changed the title With NET 5 RC1 x86 SDK installed, run Unit test failed with error: Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found... With NET 5 RC1 x86 SDK installed on x64 OS, run Unit test failed with error: Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found... Sep 2, 2020
@wli3
Copy link

wli3 commented Sep 11, 2020

@pavelhorak could you look into it?

@pavelhorak
Copy link
Member

@vdanche I cannot repro this issue on with NET 5 RC1 x86 - (5.0.100-rc.1.20454.5)

"%ProgramFiles(x86)%/dotnet/dotnet" --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100-rc.1.20454.5
 Commit:    53a032d031

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x86
 Base Path:   C:\Program Files (x86)\dotnet\sdk\5.0.100-rc.1.20454.5\

Host (useful for support):
  Version: 5.0.0-rc.1.20451.14
  Commit:  38017c3935

.NET SDKs installed:
  5.0.100-rc.1.20454.5 [C:\Program Files (x86)\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]

c:\Users\pahorak\source\repos>"%ProgramFiles(x86)%/dotnet/dotnet" new mstest -n mstestdemo
The template "Unit Test Project" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on mstestdemo\mstestdemo.csproj...
  Determining projects to restore...
  Restored c:\Users\pahorak\source\repos\mstestdemo\mstestdemo.csproj (in 1,54 sec).
Restore succeeded.


c:\Users\pahorak\source\repos>cd mstestdemo

c:\Users\pahorak\source\repos\mstestdemo>"%ProgramFiles(x86)%/dotnet/dotnet" build
Microsoft (R) Build Engine version 16.8.0-preview-20451-02+51a1071f8 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  mstestdemo -> c:\Users\pahorak\source\repos\mstestdemo\bin\Debug\net5.0\mstestdemo.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.47

c:\Users\pahorak\source\repos\mstestdemo>"%ProgramFiles(x86)%/dotnet/dotnet" test
  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  mstestdemo -> c:\Users\pahorak\source\repos\mstestdemo\bin\Debug\net5.0\mstestdemo.dll
Test run for c:\Users\pahorak\source\repos\mstestdemo\bin\Debug\net5.0\mstestdemo.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.8.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 2 ms - mstestdemo.dll (net5.0)

Can you try again? If it doesn't work share hahah.csproj project file and listing of dir C:\Users\v-danche\today\hahah

@vdanche
Copy link
Member Author

vdanche commented Sep 14, 2020

@pavelhorak, I can repro this issue on with NET 5 RC1 x86 - (5.0.100-rc.1.20454.5)
C:\Users\v-danche>"%ProgramFiles(x86)%/dotnet/dotnet" --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-rc.1.20454.5
Commit: 53a032d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x86
Base Path: C:\Program Files (x86)\dotnet\sdk\5.0.100-rc.1.20454.5\

Host (useful for support):
Version: 5.0.0-rc.1.20451.14
Commit: 38017c3935

.NET SDKs installed:
5.0.100-rc.1.20454.5 [C:\Program Files (x86)\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

C:\Users\v-danche>cd C:\Users\v-danche\test

C:\Users\v-danche\test>"%ProgramFiles(x86)%/dotnet/dotnet" new mstest -o mymstest
The template "Unit Test Project" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on mymstest\mymstest.csproj...
Determining projects to restore...
Restored C:\Users\v-danche\test\mymstest\mymstest.csproj (in 360 ms).
Restore succeeded.

C:\Users\v-danche\test>cd mymstest

C:\Users\v-danche\test\mymstest>"%ProgramFiles(x86)%/dotnet/dotnet" build
Microsoft (R) Build Engine version 16.8.0-preview-20451-02+51a1071f8 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
mymstest -> C:\Users\v-danche\test\mymstest\bin\Debug\net5.0\mymstest.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.29

C:\Users\v-danche\test\mymstest>"%ProgramFiles(x86)%/dotnet/dotnet" test
Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
mymstest -> C:\Users\v-danche\test\mymstest\bin\Debug\net5.0\mymstest.dll
Test run for C:\Users\v-danche\test\mymstest\bin\Debug\net5.0\mymstest.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.8.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 [C:\Users\v-danche\test\mymstest\bin\Debug\net5.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.

Test Run Aborted.
C:\Program Files (x86)\dotnet\sdk\5.0.100-rc.1.20454.5\Microsoft.TestPlatform.targets(32,5): error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error. [C:\Users\v-danche\test\mymstest\mymstest.csproj]

C:\Users\v-danche\test\mymstest>

@vdanche
Copy link
Member Author

vdanche commented Sep 14, 2020

My project has been attached. Thanks
mymstest.zip

@pavelhorak
Copy link
Member

The reason why I could not repro locally is that I have also x64 version of SDK installed on machine.

Now, since you are on x64 OS, regardless of having only x86 SDK, you need to implicitly build x86 version to make it work.

dotnet test -p:Platform=x86

Thank @nohwnd for helping me.

@nohwnd
Copy link
Member

nohwnd commented Sep 14, 2020

There are actually 3 ways you can fix this. I would suggest 1.:

  1. Install 64-bit SDK (or just runtime), this will allow dotnet test to find it and use it to run tests. We guess the SDK version to use from the OS architecture, so for AnyCPU DLL on 64-bit OS we guess 64-bit SDK.
  2. Tell dotnet test explicity which platform to use for the run by -p:Platform=x86.
  3. Build your DLL as x86 instead of AnyCPU.

If this is a test scenario, I think it should be re-visited. At one point in time we broke this logic and got multiple reports of dotnet test incorrectly looking for x86 SDK which was not present on the system (64-bit OS with only 64-bit SDK). I don't think we ever got the report of this inverse case (64-bit OS with only 32-bit SDK, apart from you reporting it.

@vdanche
Copy link
Member Author

vdanche commented Sep 15, 2020

Got it and will update out testcase. Thanks!

@vdanche vdanche closed this as completed Sep 15, 2020
@tannergooding
Copy link
Member

  1. Install 64-bit SDK (or just runtime), this will allow dotnet test to find it and use it to run tests.

I don't think this is a valid option. At least in my CI scenarios, I explicitly download and install the 32-bit SDK because I am testing my binaries when run under 32-bit mode.
Installing the 64-bit SDK and having it run the tests in 64-bit mode defeats that.

  1. Tell dotnet test explicity which platform to use for the run by -p:Platform=x86.

This doesn't work at the solution level and you will get an error such as:

 C:\Repos\terrafx.interop.windows\TerraFX.Interop.Windows.sln.metaproj : error MSB4126: The specified solution configuration "Debug|x86" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [C:\Repos\terrafx.interop.windows\TerraFX.Interop.Windows.sln]

Build your DLL as x86 instead of AnyCPU.

This is the same issue as 2 and shouldn't be required, IMO. You should be able to just do something akin to dotnet test --architecture x86 and have it run the tests as x86, regardless of whether you are running from a 32-bit or 64-bit SDK.
I imagine this also exists for arm vs arm64 where another Windows on Windows layer exists (and where x86 is also a valid target via the emulation layer).

If this is a test scenario, I think it should be re-visited. At one point in time we broke this logic and got multiple reports of dotnet test incorrectly looking for x86 SDK which was not present on the system (64-bit OS with only 64-bit SDK). I don't think we ever got the report of this inverse case (64-bit OS with only 32-bit SDK, apart from you reporting it.

Why is there any guessing here at all? If dotnet is 32-bit, you can safely default to running 32-bit tests. Likewise if dotnet (or other host) is 64-bit, you can safely default to it running as 64-bit.
Having the ability to explicitly specify the target such as via --architecture then provides a fallback so you can run 64-bit tests from a 32-bit SDK or vice-versa.

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 a pull request may close this issue.

5 participants