sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[NetTestingE2E][Regression] Error "The library hostfxr.dll was found..." will throw when executing "dotnet test --arch x86 --diag:log1.txt".

Open v-yifengmiao opened this issue 5 months ago • 7 comments

Notes:

1.This issue doesn't repro on 10.0.100-preview.5.25263.104. 2.Repro VM: 172.16.195.106

Repro steps:

  1. On Win 10 22H2 x64 VM: 2.Install dotnet-sdk-10.0.100-preview.6.25316.103-win-x64.exe & dotnet-sdk-10.0.100-preview.6.25316.103-win-x86.exe
  2. Launch Powershell and execute below commads:

mkdir c:\hltest\xunit2 dotnet new xunit dotnet restore dotnet build dotnet test --arch x86 --diag:log2.txt

Expected Result:

The command will run successfully.

Actual Result:

Test runs aborted.

Image

Logs:

PS C:\hltest\xunit2> dotnet test --arch x86 --diag:log2.txt Restore complete (0.8s) You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy xunit2 succeeded with 1 warning(s) (0.8s) → bin\Debug\net10.0\win-x86\xunit2.dll C:\hltest\xunit2\UnitTest1.cs(18,21): warning CS8602: Dereference of a possibly null reference. Logging Vstest Diagnostics in file: C:\hltest\xunit2\log1.txt Failed to load the dll from [C:\Program Files\dotnet\host\fxr\10.0.0-preview.6.25316.103\hostfxr.dll], HRESULT: 0x800700C1 The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\10.0.0-preview.6.25316.103\hostfxr.dll failed

  • Installing .NET prerequisites might help resolve this problem. https://go.microsoft.com/fwlink/?linkid=798306 Testhost process for source(s) 'C:\hltest\xunit2\bin\Debug\net10.0\win-x86\xunit2.dll' exited with error: Failed to load the dll from [C:\Program Files\dotnet\host\fxr\10.0.0-preview.6.25316.103\hostfxr.dll], HRESULT: 0x800700C1 The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\10.0.0-preview.6.25316.103\hostfxr.dll failed
  • Installing .NET prerequisites might help resolve this problem. https://go.microsoft.com/fwlink/?linkid=798306 . Please check the diagnostic logs for more information. xunit2 test failed with 1 error(s) (0.8s) C:\hltest\xunit2\bin\Debug\net10.0\win-x86\xunit2.dll : error TESTRUNABORT: Test Run Aborted.

Build failed with 1 error(s) and 1 warning(s) in 3.1s

Log2.txt: Detailed info please refer to attached file: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. at System.Reflection.RuntimeModule.GetDefinedTypes() at System.Reflection.RuntimeModule.GetTypes() at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginDiscoverer.GetTestExtensionsFromAssembly[TPluginInfo,TExtension](Assembly assembly, Dictionary`2 pluginInfos, String filePath) in D:\a_work\1\s\src\vstest\src\Microsoft.TestPlatform.Common\ExtensionFramework\TestPluginDiscoverer.cs:line 159 System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginCache.CurrentDomainAssemblyResolve(Object sender, AssemblyResolveEventArgs args) in D:\a_work\1\s\src\vstest\src\Microsoft.TestPlatform.Common\ExtensionFramework\TestPluginCache.cs:line 514 at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName) System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' TpTrace Warning: 0 : 15176, 2, 2025/06/17, 02:51:05.822, 56111809314, vstest.console.dll, LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginCache.CurrentDomainAssemblyResolve(Object sender, AssemblyResolveEventArgs args) in D:\a_work\1\s\src\vstest\src\Microsoft.TestPlatform.Common\ExtensionFramework\TestPluginCache.cs:line 514 at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)

dotnet --info:

PS C:\Windows\system32> dotnet --info .NET SDK: Version: 10.0.100-preview.6.25316.103 Commit: 20343176cf Workload version: 10.0.100-manifests.dd8061fd MSBuild version: 17.15.0-preview-25316-103+20343176c

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.6.25316.103\

.NET workloads installed: There are no installed workloads to display. Configured to use workload sets when installing new manifests. Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host: Version: 10.0.0-preview.6.25316.103 Architecture: x64 Commit: 20343176cf

.NET SDKs installed: 10.0.100-preview.6.25316.103 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 10.0.0-preview.6.25316.103 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 10.0.0-preview.6.25316.103 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 10.0.0-preview.6.25316.103 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

&'C:\Program Files (x86)\dotnet\dotnet.exe' --info:

PS C:\Windows\system32> & 'C:\Program Files (x86)\dotnet\dotnet.exe' --info .NET SDK: Version: 10.0.100-preview.6.25316.103 Commit: 20343176cf Workload version: 10.0.100-manifests.dd8061fd MSBuild version: 17.15.0-preview-25316-103+20343176c

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x86 Base Path: C:\Program Files (x86)\dotnet\sdk\10.0.100-preview.6.25316.103\

.NET workloads installed: There are no installed workloads to display. Configured to use workload sets when installing new manifests. Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host: Version: 10.0.0-preview.6.25316.103 Architecture: x86 Commit: 20343176cf

.NET SDKs installed: 10.0.100-preview.6.25316.103 [C:\Program Files (x86)\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 10.0.0-preview.6.25316.103 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 10.0.0-preview.6.25316.103 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 10.0.0-preview.6.25316.103 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x64 [C:\Program Files\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

log2.txt

v-yifengmiao avatar Jun 17 '25 02:06 v-yifengmiao

This issue also reproduces on Win ARM and Mac M1 OS when executing below commands:

  1. On Win ARM: install net10 arm64, x64,x86 sdk and x64 runtime for .NET6.0.
  2. Launch Powershell and execute below commads:

dotnet new xunit Add below contents into the *.csproj file: <TargetFrameworks>net10.0;net6.0</TargetFrameworks> <LangVersion>latest</LangVersion> dotnet build dotnet test --framework net6.0 --diag:loga.txt

Image PS C:\hltestm1\xunithl1> dotnet test --framework net6.0 --diag:loga.txt You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy xunithl1 net6.0 succeeded (0.4s) → bin\Debug\net6.0\xunithl1.dll Logging Vstest Diagnostics in file: C:\hltestm1\xunithl1\loga.txt You must install or update .NET to run this application. App: C:\Program Files\dotnet\sdk\10.0.100-preview.6.25316.103\testhost.dll Architecture: arm64 Framework: 'Microsoft.NETCore.App', version '6.0.0' (arm64) .NET location: C:\Program Files\dotnet
The following frameworks were found: 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] The following frameworks for other architectures were found: x64 6.0.36 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App] 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App] x86 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Learn more: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=arm64&rid=win-arm64&os=win10 Testhost process for source(s) 'C:\hltestm1\xunithl1\bin\Debug\net6.0\xunithl1.dll' exited with error: You must install or update .NET to run this application. App: C:\Program Files\dotnet\sdk\10.0.100-preview.6.25316.103\testhost.dll Architecture: arm64 Framework: 'Microsoft.NETCore.App', version '6.0.0' (arm64) .NET location: C:\Program Files\dotnet
The following frameworks were found: 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] The following frameworks for other architectures were found: x64 6.0.36 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App] 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App] x86 8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 10.0.0-preview.6.25316.103 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Learn more: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=arm64&rid=win-arm64&os=win10 . Please check the diagnostic logs for more information. xunithl1 test net6.0 failed with 1 error(s) (0.9s) C:\hltestm1\xunithl1\bin\Debug\net6.0\xunithl1.dll : error TESTRUNABORT: Test Run Aborted.

Build failed with 1 error(s) in 1.5s PS C:\hltestm1\xunithl1>

TpTrace Warning: 0 : 6708, 2, 2025/06/17, 08:35:37.684, 241493575156, vstest.console.dll, TestPluginDiscoverer: Failed to get types from assembly 'Microsoft.Diagnostics.NETCore.Client, Version=0.2.12.31703, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Error: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. at System.Reflection.RuntimeModule.GetDefinedTypes() at System.Reflection.RuntimeModule.GetTypes() at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginDiscoverer.GetTestExtensionsFromAssembly[TPluginInfo,TExtension](Assembly assembly, Dictionary`2 pluginInfos, String filePath) in D:\a_work\1\s\src\vstest\src\Microsoft.TestPlatform.Common\ExtensionFramework\TestPluginDiscoverer.cs:line 159 System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginCache.CurrentDomainAssemblyResolve(Object sender, AssemblyResolveEventArgs args) in D:\a_work\1\s\src\vstest\src\Microsoft.TestPlatform.Common\ExtensionFramework\TestPluginCache.cs:line 514 at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)

v-hozha1 avatar Jun 17 '25 08:06 v-hozha1

The error says that you are missing net6 runtime for arm64, you have x64 version installed. But because you are on arm64 device and you don't specify preference for architecture, then arm64 is used (based on OS architecture).

Testhost process for source(s) 'C:\hltestm1\xunithl1\bin\Debug\net6.0\xunithl1.dll' exited with error: You must install or update .NET to run this application.

The following frameworks were found:
8.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
10.0.0-preview.6.25316.103 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

The following frameworks for other architectures were found:
x64
6.0.36 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]

Please install the runtime for the application you are trying to run, with the correct architecture and try again if that solves the problem.

nohwnd avatar Jun 17 '25 15:06 nohwnd

@nohwnd Following our test scenarios, I think we're not missing any runtime for all platforms (win x64\win ARM64\Mac M1). We can executed theses commands which descripted in original issue or commented issue successfully with the same setup configurations( .NET10 P5 SDKs + .netcoreapp3.1 or .net5 x64 runtime). Now, as security issues of out-of-supported runtimes, we replace netcoreapp3.1 or .net5 x64 runtimes with .NET6 runtime. validate with the combination "the latest .NET 10 P6 SDKs + .NET6 runtime".

**Here're the testing results on .NET10 P5 & .NET10 P6 builds for reference: ** Win x64: .NET10 P5 SDKs - Pass .NET10 P6 SDKs - Fail with this issue Image

Win ARM64: .NET10 P5 SDKs + .netcoreapp3.1 x64 runtime - Pass .NET 10 P6 SDKs + .NET6.0 x64 runtime - Fail with this issue Image

Mac M1: .NET10 P5 SDKs + .net5.0 x64 runtime - Pass .NET 10 P6 SDKs + .NET6.0 x64 runtime - Fail with this issue Image

v-hozha1 avatar Jun 18 '25 00:06 v-hozha1

For the original issue I installed net10 in x64 and x86 from latest build and I don't see the issue:

Image

The reported issue seems intermittent. Either the installation is corrupted on the OS (which happened many times in the past), or that particular installer is broken. Is the version you are validating some candidate for release or random version that is being tested?


For the screenshots in your last post, I am not sure what I should be seeing there. I assume you are writing the process info via an exception and the tests are able to run to the end, with 1 failed test. Right?

The two screens show that on netcoreapp3.1 and net5 the x64 runtime is selected. But then you say that it fails for net6, and there is no screenshot for that, correct?

If that is the case then this is by design and you are running into this:

https://github.com/microsoft/vstest/blob/main/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs#L606-L619

On netcoreapp3.1 and net5 on mac arm64 we prefer x64, because arm64 runtime is not available for those versions. On net6 and newer on mac + arm64 we prefer arm64 runtime, because the runtime is available for net6 and newer.

So you are probably missing the arm64 runtime, to be able to run net6 tests.

nohwnd avatar Jun 18 '25 07:06 nohwnd

@nohwnd Here're my comments for above quires. If I'm missing any question, please let me know freely.

  • Test Build link: We validate the main sdk build from https://github.com/dotnet/dotnet/blob/main/docs/builds-table.md. Sampe Code: SampleCode (2).txt

  • I tried this issue again with the above reproduced steps on win x64, this issue still occurs consistently. Here is the repro VM for reference: 10.158.80.16 (Your account has been added into this VM.) Steps:

Install dotnet-sdk-10.0.100-preview.6.25317.108-win-x64.exe & dotnet-sdk-10.0.100-preview.6.25317.108-win-x86.exe Launch PowerShell and execute below commands: mkdir c:\hltest\xunit2 dotnet new xunit dotnet restore dotnet build dotnet test --arch x86 --diag:log2.txt

log2.txt please refer to: loaga.txt

Image

Image

  • The failed screenshots for net6 are attached in first comments. So, I didn't re-attach them in the comments again. Attaching the screenshot again with .NET6 arm64 runtime installed: On Win ARM64 machine, although installing .NET6 arm64 runtime, this issue still reproduces. Here is the reproduces Win ARM VM from reference: 172.20.30.182 On Win ARM: install net10 arm64, x64,x86 sdk and ARM runtime for .NET6.0. Launch Powershell and execute below commads: dotnet new xunit Add below contents into the *.csproj file: <TargetFrameworks>net10.0;net6.0</TargetFrameworks> <LangVersion>latest</LangVersion> dotnet build dotnet test --framework net6.0 --diag:loga1.txt

loga1.txt please refer to: loga1.txt

Image

v-hozha1 avatar Jun 18 '25 09:06 v-hozha1

I can repro it now, the problem is that dotnet_root gets set via vstest_winapphost_dotnet_root = c:\program files\dotnet, which makes the x86 app use the x64 runtime. Investigating what changed. Because this was added to support the --arch parameter and was working in the past.

nohwnd avatar Jun 18 '25 11:06 nohwnd

Image Can also repro on net9 sdk.

nohwnd avatar Jun 19 '25 13:06 nohwnd

This issue still reproduces on .NET10 P6 sign-off build - 10.0.100-preview.6.25321.102. .NET9 - Pass .NET10 P5 - Pass .NET10 P6 - Fail with this issue

Image

Image

v-hozha1 avatar Jun 25 '25 01:06 v-hozha1

@v-hozha1 can you check the version of Microsoft.NET.Test.Sdk for the projects? I was able to reproduce this issue with just .NET 9.0 SDK installed, by upgrading the version of Microsoft.NET.Test.Sdk to 17.14 and running dotnet restore; dotnet test --arch x86.

The version 17.13 runs the same scenario successfully.

drognanar avatar Jun 26 '25 14:06 drognanar

In 17.14, the testhost is net8.0, while it was netcoreapp3.1 previously. And the behavior difference is coming from there.

We are running testhost.x86.exe with DOTNET_ROOT pointing out to C:/Program Files/dotnet.

Either .NET SDK or vstest.console.exe is doing something wrong with DOTNET_ROOT. But at the same time I was expecting DOTNET_ROOT to have no effect at all when running 32-bit apphost on 64-bit OS. My expectation is that DOTNET_ROOT_X86 is what should be used. @agocke Can you give me some more info on this, and on the behavior difference between netcoreapp3.1 and net8.0?

Youssef1313 avatar Jun 26 '25 15:06 Youssef1313

Using 17.13 (where testhost.x86.exe is netcoreapp3.1), I see

Using global installation location [C:\Program Files (x86)\dotnet\] as runtime location.

Using 17.14 (where testhost.x86.exe is .NET 8), I see

Using environment variable DOTNET_ROOT=[C:\Program Files\dotnet] as runtime location.

Youssef1313 avatar Jun 26 '25 15:06 Youssef1313

It looks like the logic will prefer DOTNET_ROOT_X86 but still falls back to DOTNET_ROOT

https://github.com/dotnet/runtime/blob/f77f791953e7e8af4bd1ce33981a9059f4c9f207/src/native/corehost/hostmisc/utils.cpp#L373-L376

Youssef1313 avatar Jun 26 '25 15:06 Youssef1313

Going in history to very old commit in dotnet/runtime:

https://github.com/dotnet/runtime/blob/f8976a5121b0728679279308d44af1965a9e5ca8/src/installer/corehost/cli/hostmisc/utils.cpp#L351-L359

https://github.com/dotnet/runtime/blob/f8976a5121b0728679279308d44af1965a9e5ca8/src/installer/corehost/cli/fxr_resolver.cpp#L71-L88

It looks like the fallback to DOTNET_ROOT isn't there.

Youssef1313 avatar Jun 26 '25 16:06 Youssef1313

Behavior change was introduced by https://github.com/dotnet/runtime/pull/53763

Youssef1313 avatar Jun 26 '25 16:06 Youssef1313

https://github.com/dotnet/sdk/blob/6142428c690f7c5bd11537e9d55764094055c814/src/Cli/dotnet/Commands/Test/VSTestForwardingApp.cs#L41-L50

This logic looks wrong to me. VSTEST_WINAPPHOST_<ENV> causes testhost to start with <ENV> to the same value (where <ENV> is either DOTNET_ROOT or DOTNET_ROOT(X86)).

The logic is wrong because, if the SDK architecture doesn't match the target architecture, we are setting the wrong thing.

So, if dotnet.exe is 64-bit, and target architecture is x86 (which is the case broken today), we are setting DOTNET_ROOT to 64-bit installation which then gets used in testhost.x86.exe.

I think we can/should only set VSTEST_WINAPPHOST_ if the current architecture matches the target architecture.

Youssef1313 avatar Jun 26 '25 16:06 Youssef1313

For reference about all architectures falling back to DOTNET_ROOT if the architecture-specific environment variable doesn't exist (added in .NET 6): https://github.com/dotnet/designs/blob/97ec4c1b25df1be318de66aa68645c422afa29dc/accepted/2021/install-location-per-architecture.md#evolve-environment-variable-overrides

elinor-fung avatar Jun 26 '25 19:06 elinor-fung

Thanks @elinor-fung. Good to know the motivation for the change introduced in net6.0.

Now need to figure out the best way to fix this. Ideally we would just fix the logic in SDK to set VSTEST_WINAPPHOST_ if current and target architectures match. But this means we will still be broken on .NET 9 SDK unless we can backport.

Otherwise, we will need to hack something in VSTest itself. A hack in VSTest could be something like finding the architecture of the dotnet executable pointed out by VSTEST_WINAPPHOST_DOTNET_ROOT, and if it's not matching the target architecture, we ignore the env variable.

Youssef1313 avatar Jun 26 '25 19:06 Youssef1313

Ideally we would just fix the logic in SDK to set VSTEST_WINAPPHOST_ if current and target architectures match. But this means we will still be broken on .NET 9 SDK unless we can backport.

Also 8.0, right (assuming you can just use a newer Microsoft.NET.Test.Sdk version and build with the 8.0 SDK)? I'd think it's worth trying for the backport. Unless you or your team thinks it is really risky, the scenario regression seems like a good argument for backporting.

elinor-fung avatar Jun 26 '25 20:06 elinor-fung

Yeah .NET 8 SDK as well will likely need a backport if we fix in SDK and not hack it in VSTest. @baronfel Is it okay to have a fix here backported?

Youssef1313 avatar Jun 26 '25 20:06 Youssef1313

That's more of a question for Tactics - you can send mail to temperature check their thoughts on it, or we can bring it up next Tuesday. The discussion will be mostly around risk of the change, impact in terms of number/importance of users, if there are key internal or external partners behind the request, etc.

baronfel avatar Jun 26 '25 20:06 baronfel

As far as I can tell we have 1 or two reports of this issue from our own testers, and no report from customers. So to me it does not seem like a high importance scenario that we should backport and fix in all the versions of net9 and net8.

Otherwise, we will need to hack something in VSTest itself. A hack in VSTest could be something like finding the architecture of the dotnet executable pointed out by VSTEST_WINAPPHOST_DOTNET_ROOT, and if it's not matching the target architecture, we ignore the env variable.

This would still require fix in vstest.console (https://grep.app/search?q=VSTEST_WINAPPHOST), and insertion into dotnet/sdk of the respective version, so it is probably easier to figure out the solution in dotnet/sdk and fix it there.

nohwnd avatar Jul 01 '25 07:07 nohwnd

Ahh yes. Updating Microsoft.NET.Test.Sdk package won't use a newer version of vstest.console, it only uses newer version of testhost. The workaround has to be in vstest.console so it really needs to be an SDK fix. 😕

Youssef1313 avatar Jul 01 '25 08:07 Youssef1313

This issue is also repro for latest dotnet-sdk-10.0.100-preview.7.25358.102. Image

v-huanli1 avatar Jul 09 '25 01:07 v-huanli1

@nohwnd We are starting to receive more complaints about this, and I'm not sure if we will now want to backport for .NET 9 SDK.

Youssef1313 avatar Jul 26 '25 09:07 Youssef1313

@nohwnd This issue still reproduces on latest .NET10 P7 build - 10.0.100-preview.7.25380.105. Would you please confirm that this fixed in .NET10 P7 or .NET 10 RC build? Thanks in advance.

https://dev.azure.com/dnceng/internal/_build/results?buildId=2761635&view=artifacts&pathAsName=false&type=publishedArtifacts Image

v-hozha1 avatar Jul 31 '25 04:07 v-hozha1

checked again today, the updated code is still not in the latest build of rc1

Image

but the code is merged to main.

nohwnd avatar Aug 04 '25 13:08 nohwnd

This isn't fixed with current SDK Version: 9.0.304. Could you please keep this open until a fix is released?

KL-Sven avatar Aug 07 '25 13:08 KL-Sven

Issue has been fixed on today's .NET10 RC1 build - 10.0.100-rc.1.25409.103. But I have no permission to close this ticket. Thanks.

Image

v-hozha1 avatar Aug 11 '25 01:08 v-hozha1

Thanks for validating @v-hozha1!

baronfel avatar Aug 11 '25 01:08 baronfel

as mentioned above please keep opened until we service it in net9.

nohwnd avatar Aug 11 '25 12:08 nohwnd