microsoft / vstest

Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
MIT License
870 stars 316 forks source link

Testhost process for source(s) '[...]/My.Library.UnitTests.dll' exited with error: Cannot open assembly '[...]/../TestHostNetFramework/testhost.net472.exe': No such file or directory #4295

Closed dhabierre closed 1 week ago

dhabierre commented 1 year ago

Description

At present time I am using Azure DevOps Pipeline with VSTest@2 task to execute Unit Tests:

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(buildConfiguration)\*test*.dll
     !**\obj\**
    vstestLocationMethod: location
    vstestLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe'
    runInParallel: false
    runTestsInIsolation: true
    codeCoverageEnabled: true
    publishRunAttachments: false
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

My goal: trying to do this using Docker Mono.

Steps to reproduce

docker pull mono:6.12.0.182

docker run -it --name mono-nuget -v C:\DEV\My.Library:/src mono:6.12.0.182

nuget restore "/src/My.Library.sln"

msbuild /p:Configuration="Release" /p:Platform="Any CPU" "/src/My.Library.sln" -m

cd /src/packages

nuget install Microsoft.TestPlatform -version 17.4.1

mono /src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/vstest.console.exe "/src/**/bin/Release/*UnitTests*.dll" /InIsolation /Logger:"trx" /EnableCodeCoverage /ResultsDirectory:"/src/TestResults"

Expected behavior

Succeeded operation.

Actual behavior

root@58afa969d5ac:/src/packages# mono /src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/vstest.console.exe "/src/Tests/UnitTests/My.Library.UnitTests/bin/Release/My.Library.UnitTests.dll" /Logger:"trx" /EnableCodeCoverage /ResultsDirectory:"/src/TestResults"
Microsoft (R) Test Execution Command Line Tool Version 17.4.1 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
0.5808
Testhost process for source(s) '/src/Tests/UnitTests/My.Library.UnitTests/bin/Release/My.Library.UnitTests.dll' exited with error: Cannot open assembly '/src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/Extensions/../TestHostNetFramework/testhost.net472.exe': No such file or directory.
. Please check the diagnostic logs for more information.
Data collector 'Code Coverage' message: No code coverage data available. Profiler was not initialized. Verify that glibc (>=2.27), libxml2 and all .NET dependecies are installed..
Results File: /src/TestResults/_58afa969d5ac_2023-02-10_09_27_57.trx

Test Run Aborted.

💡 UnitTests project is written using .net 4.7.2

Any help is welcome :) Thanks!

nohwnd commented 1 year ago

Please run it with --diag:logs/log.txt and post the logs folder. If you can.

I cannot repro on windows. The code here has some special cases for windows so we are probably doing it wrong for mono: https://github.com/microsoft/vstest/blob/main/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs#L160

dhabierre commented 1 year ago

Hi @nohwnd and thank you for your help.

Here the logfiles:

log.txt log.datacollector.23-02-10_12-17-51_35700_1.txt

Some of them:

log.txt

TpTrace Warning: 0 : 878, 10, 2023/02/10, 12:17:53.712, 676185890859, vstest.console.exe, TestHostManagerCallbacks.ErrorReceivedCallback Test host standard error line: Cannot open assembly '/src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/Extensions/../TestHostNetFramework/testhost.net472.exe': No such file or directory.
TpTrace Warning: 0 : 878, 11, 2023/02/10, 12:17:53.717, 676185940544, vstest.console.exe, TestHostManagerCallbacks.ErrorReceivedCallback Test host standard error line: 
TpTrace Verbose: 0 : 878, 11, 2023/02/10, 12:17:53.721, 676185983927, vstest.console.exe, TestHostProvider.ExitCallBack: Host exited starting callback.
TpTrace Error: 0 : 878, 11, 2023/02/10, 12:17:53.722, 676185995629, vstest.console.exe, TestHostManagerCallbacks.ExitCallBack: Testhost processId: 895 exited with exitcode: 2 error: 'Cannot open assembly '/src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/Extensions/../TestHostNetFramework/testhost.net472.exe': No such file or directory.'
TpTrace Verbose: 0 : 878, 11, 2023/02/10, 12:17:53.723, 676186003786, vstest.console.exe, CrossPlatEngine.TestHostManagerHostExited: calling on client process exit callback.
TpTrace Information: 0 : 878, 11, 2023/02/10, 12:17:53.724, 676186010203, vstest.console.exe, TestRequestSender.OnClientProcessExit: Test host process exited. Standard error: Cannot open assembly '/src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/Extensions/../TestHostNetFramework/testhost.net472.exe': No such file or directory.
TpTrace Verbose: 0 : 878, 8, 2023/02/10, 12:17:53.724, 676186014462, vstest.console.exe, TestRequestSender.WaitForRequestHandlerConnection: waiting took 50 ms, with timeout 90000 ms, and result 2, which is failure.
TpTrace Verbose: 0 : 878, 8, 2023/02/10, 12:17:53.725, 676186019634, vstest.console.exe, Test host failed to start Test host launched:True test host exited: True
TpTrace Error: 0 : 878, 8, 2023/02/10, 12:17:53.726, 676186038102, vstest.console.exe, ProxyExecutionManager.StartTestRun: Failed to start test run: Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process for source(s) '/src/Tests/UnitTests/My.Library.UnitTests/bin/Release/My.Library.UnitTests.dll' exited with error: Cannot open assembly '/src/packages/Microsoft.TestPlatform.17.4.1/tools/net462/Common7/IDE/Extensions/TestPlatform/Extensions/../TestHostNetFramework/testhost.net472.exe': No such file or directory.
. Please check the diagnostic logs for more information.
  at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited (System.Collections.Generic.IEnumerable`1[T] sources, System.Boolean testHostExited) [0x00028] in <bd9f713922bb4b768929ee34d7709754>:0 
  at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel (System.Collections.Generic.IEnumerable`1[T] sources, System.String runSettings) [0x002a9] in <bd9f713922bb4b768929ee34d7709754>:0 
  at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun (Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCriteria testRunCriteria, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.IInternalTestRunEventsHandler eventHandler) [0x000dc] in <bd9f713922bb4b768929ee34d7709754>:0 

log.datacollector.23-02-10_12-17-51_35700_1.txt

TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.629, 676185063355, datacollector.exe, DataCollectionRequestHandler.ProcessRequests : DataCollection started.
TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.668, 676185453727, datacollector.exe, DataCollectionRequestHandler.ProcessRequests: Datacollector received message: (DataCollection.TestHostLaunched) -> {"MessageType":"DataCollection.TestHostLaunched","Payload":{"ProcessId":895}}
TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.673, 676185499710, datacollector.exe, DynamicCoverageDataCollector.TestHostLaunched: TestHostLaunched event received: ProcessId: 895
TpTrace Error: 0 : 883, 1, 2023/02/10, 12:17:53.710, 676185872288, datacollector.exe, MulticastDelegateUtilities.SafeInvoke: 1: Invoking callback 2/Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorWithAttachmentProcessor for .DataCollectionEvents.TestHostLaunched, failed after 37 ms with: 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 Microsoft.VisualStudio.Coverage.ManagedVanguard.set_TestHostProcessId (System.Int32 value) [0x00000] in <40286983009f4b1cae82b7cb6973b886>:0 
  at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.TestHostLaunched (System.Object sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.TestHostLaunchedEventArgs e) [0x00030] in <40286983009f4b1cae82b7cb6973b886>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <de882a77e7c14f8ba5d298093dde82b2>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at Microsoft.VisualStudio.TestPlatform.Utilities.MulticastDelegateUtilities.SafeInvoke (System.Delegate delegates, System.Object sender, System.Object args, System.String traceDisplayName) [0x0004e] in <ea3d614f92e940729b2038eda79a1bd4>:0 .
TpTrace Verbose: 0 : 883, 1, 2023/02/10, 12:17:53.710, 676185878468, datacollector.exe, MulticastDelegateUtilities.SafeInvoke: DataCollectionEvents.TestHostLaunched: Invoking callback 2/2 for Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorWithAttachmentProcessor., took 0 ms.
TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.753, 676186303875, datacollector.exe, DataCollectionRequestHandler.ProcessRequests: Datacollector received message: (DataCollection.AfterTestRunEnd) -> {"MessageType":"DataCollection.AfterTestRunEnd","Payload":false}
TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.756, 676186334071, datacollector.exe, DynamicCoverageDataCollectorImpl.StopVanguard: Calling Stop Vanguard. datacollection context sessionID: {312bb6a7-b19e-4141-ad32-0eba6b35b012}, number of clients connected: 0
TpTrace Information: 0 : 883, 1, 2023/02/10, 12:17:53.757, 676186339393, datacollector.exe, ManagedVanguard.Stop: Stopping VanguardLogger.
TpTrace Warning: 0 : 883, 1, 2023/02/10, 12:17:53.757, 676186346460, datacollector.exe, DynamicCoverageDataCollectorImpl.StopVanguard: No code coverage data available. Profiler was not initialized. Verify that glibc (>=2.27), libxml2 and all .NET dependecies are installed.
TpTrace Warning: 0 : 883, 1, 2023/02/10, 12:17:53.758, 676186352927, datacollector.exe, Data collector 'datacollector://microsoft/CodeCoverage/2.0' logged the following warning: No code coverage data available. Profiler was not initialized. Verify that glibc (>=2.27), libxml2 and all .NET dependecies are installed.
TpTrace Verbose: 0 : 883, 1, 2023/02/10, 12:17:53.759, 676186365921, datacollector.exe, MulticastDelegateUtilities.SafeInvoke: DataCollectionEvents.SessionEnd: Invoking callback 1/2 for Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorWithAttachmentProcessor., took 3 ms.
TpTrace Error: 0 : 883, 1, 2023/02/10, 12:17:53.762, 676186398843, datacollector.exe, MulticastDelegateUtilities.SafeInvoke: 2: Invoking callback 2/Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorWithAttachmentProcessor for .DataCollectionEvents.SessionEnd, failed after 1 ms with: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.EntryPointNotFoundException: QueryPerformanceCounter assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Microsoft.VisualStudio.IntelliTrace.HighPerformanceTimer+NativeMethods.QueryPerformanceCounter(long&)
  at Microsoft.VisualStudio.IntelliTrace.HighPerformanceTimer.QueryPerformanceCounter () [0x00003] in <f3073d227ee94eada6857afaeb55a343>:0 
  at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.OnSessionEnd (System.Object sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.SessionEndEventArgs e) [0x00020] in <40286983009f4b1cae82b7cb6973b886>:0 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <de882a77e7c14f8ba5d298093dde82b2>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0 
  at Microsoft.VisualStudio.TestPlatform.Utilities.MulticastDelegateUtilities.SafeInvoke (System.Delegate delegates, System.Object sender, System.Object args, System.String traceDisplayName) [0x0004e] in <ea3d614f92e940729b2038eda79a1bd4>:0 .

The same command in a Docker Windows (mcr.microsoft.com/dotnet/framework/sdk:4.8) is OK.

"C:\Program Files (x86)\Microsoft Visual Studio\2022\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "C:\src\**\bin\Release\*UnitTests*.dll" /InIsolation /Logger:"trx" /EnableCodeCoverage /ResultsDirectory:"C:\src\TestResults"
nohwnd commented 1 week ago

I've dropped the ball on this one, I am sorry. I hope you found what the issue was.