msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[WINARM][Regression] Hangs when running the command – Hangs when running the command - &"C:\Program Files\dotnet\x64\dotnet.exe" test.

Open WenJunJi01 opened this issue 3 years ago • 4 comments

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:

  1. $env:DOTNET_MULTILEVEL_LOOKUP=0
  2. ls env:
  3. dotnet new mstest
  4. 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>
  1. dotnet test --framework net7.0 --diag:loga.txt
  2. &"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.

  1. &"C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --diag:log3.txt image
  2. & "C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --arch arm64 --diag:log.txt image
  3. & "C:\Program Files\dotnet\x64\dotnet.exe" test --framework net7.0 --arch x86 --diag:log image

WenJunJi01 avatar Jun 21 '22 03:06 WenJunJi01

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

--Screenshot: image

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

v-hozha1 avatar Jul 11 '22 04:07 v-hozha1

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?

benvillalobos avatar Jul 12 '22 22:07 benvillalobos

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.

rainersigwald avatar Jul 15 '22 14:07 rainersigwald

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.

AR-May avatar Aug 02 '22 15:08 AR-May

This issue cannot repro with dotnet-sdk-7.0.100-rc.1.22415.27-win-x64 today. image

WenJunJi01 avatar Aug 16 '22 09:08 WenJunJi01

@AR-May can you verify that it doesn't repro on dotnet-sdk-7.0.100-rc.1.22415.27-win-x64?

benvillalobos avatar Sep 06 '22 16:09 benvillalobos

@BenVillalobos I confirm, issue doesn't repro anymore.

AR-May avatar Sep 07 '22 17:09 AR-May

Close it as not repro.

WenJunJi01 avatar Sep 14 '22 09:09 WenJunJi01