msbuild
msbuild copied to clipboard
[WINARM][Regression] Hangs when running the command – Hangs when running the command - &"C:\Program Files\dotnet\x64\dotnet.exe" test.
Note: 1.It’s regression issue. It doesn’t repro on dotnet-sdk-7.0.100-preview.5.22225.1-win-arm64. 2. Repro VM: vsengarmsfx041
Builds info: dotnet-runtime-3.1.22-win-x64 dotnet-sdk-6.0.301-win-x64 dotnet-sdk-7.0.100-preview.6.22316.8-win-arm64 dotnet-sdk-7.0.100-preview.6.22316.8-win-x64 dotnet-sdk-7.0.100-preview.6.22316.8-win-x86
Build Link: https://aka.ms/dotnet/7.0.1xx/daily/dotnet-sdk-win-arm64.exe https://aka.ms/dotnet/7.0.1xx/daily/dotnet-sdk-win-x64.exe https://aka.ms/dotnet/7.0.1xx/daily/dotnet-sdk-win-x86.exe https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-3.1.22-windows-x64-installer
Steps: Execute the following commands by Powershell:
- $env:DOTNET_MULTILEVEL_LOOKUP=0
- ls env:
- dotnet new mstest
- Update file UnitTest1.cs with
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
namespace CreateScenarioForVendors
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.AppendLine();
foreach (DictionaryEntry var in Environment.GetEnvironmentVariables())
{
if(var.Key.ToString().StartsWith("DOTNET_"))
{
builder.AppendLine($"{var.Key.ToString()} {var.Value}");
}
}
builder.AppendLine();
builder.AppendLine();
builder.AppendLine($"ProcessArchitecture {System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString()}");
builder.AppendLine($"Location {typeof(object).Assembly.Location}");
builder.AppendLine($"Process name {Process.GetCurrentProcess().Modules[0].FileName}");
throw new Exception(builder.ToString());
}
}
}
Update the project file in in this way
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version=" 17.1.0-preview-20211130-02" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>
</Project>
- dotnet test --framework net7.0 --diag:loga.txt
- &"C:\Program Files (x86)\dotnet\dotnet.exe" test
Expected Result: The command should be run normally.
Actual Results: Hangs when running the command – Hangs when running the command - &"C:\Program Files\dotnet\x64\dotnet.exe" test.
- &"C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --diag:log3.txt

- & "C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --arch arm64 --diag:log.txt

- & "C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --arch x86 --diag:log

I also repro this issue on dotnet-sdk-7.0.100-preview.7.22358.13.
--Screenshot:

PS C:\tmp\mstest> &"C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --diag:log4q.txt Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at InvokeStub_Assembly.get_Location(Object, Object, IntPtr*) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) --- End of inner exception stack trace --- at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance() at Microsoft.Build.CommandLine.MSBuildApp.ConstructArrayArg(String[] args) at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args) at Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.ExecuteInProc(String[] arguments) PS C:\tmp\mstest> &"C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --diag:log3a.txt
Looks like BuildEnvironmentHelper is failing on finding where msbuild is currently located? get_Instance is the auto-generated method for the getter.
Seems to be somewhere in the initialize method that things go wrong. It looks like it's this exact line, at the getter for Location within Assembly. So assembly is null here?
https://github.com/dotnet/msbuild/blob/7d628917b66fcfc524fa42bc3f07aab4605d35ec/src/Shared/BuildEnvironmentHelper.cs#L100-L117
@rainersigwald does this seem directly msbuild related?
We shouldn't be in that "none" mode for any .NET SDK scenario, I don't think, so it's probably our problem in an earlier codepath.
It seems that I ran into the issue as well. The easier repro steps:
dotnet new console
&"C:\Program Files\dotnet\x64\dotnet.exe" build
It hangs.
This issue cannot repro with dotnet-sdk-7.0.100-rc.1.22415.27-win-x64 today.

@AR-May can you verify that it doesn't repro on dotnet-sdk-7.0.100-rc.1.22415.27-win-x64?
@BenVillalobos I confirm, issue doesn't repro anymore.
Close it as not repro.