Here are the logs I got from the Azure DevOps pipeline.
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test C:\Agents\AG3-1\_work\115\s\src\My.Project.UnitTests\My.Project.UnitTests.csproj --logger trx --results-directory C:\Agents\AG3-1\_work\_temp --configuration Release --logger trx "--collect:Code Coverage"
Determining projects to restore...
All projects are up-to-date for restore.
My.Project -> C:\Agents\AG3-1\_work\115\s\src\My.Project\bin\Release\net8.0\My.Project.dll
My.Project.UnitTests -> C:\Agents\AG3-1\_work\115\s\src\My.Project.UnitTests\bin\Release\net8.0\My.Project.UnitTests.dll
Test run for C:\Agents\AG3-1\_work\115\s\src\My.Project.UnitTests\bin\Release\net8.0\My.Project.UnitTests.dll (.NETCoreApp,Version=v8.0)
VSTest version 17.12.0 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BufferedStream.Flush()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.WriteAndFlushToChannel(String rawMessage) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs:line 413
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestSender.SendAfterTestRunEndAndGetResult(ITestMessageEventHandler runEventsHandler, Boolean isCancelled) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs:line 155
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.<>c__DisplayClass20_0.<AfterTestRunEnd>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 155
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 288
Results File: C:\Agents\AG3-1\_work\_temp\svc_AG3-1_ag3_2025-03-31_02_34_10.trx
Passed! - Failed: 0, Passed: 12, Skipped: 0, Total: 12, Duration: 1 s - My.Project.UnitTests.dll (net8.0)
[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: / and / . To learn about more such changes and troubleshoot, refer here: #troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : [
'C:\\Agents\\AG3-1\\_work\\115\\s\\src\\My.Project.UnitTests\\My.Project.UnitTests.csproj'
]
Async Command Start: Publish test results
Publishing test results to test run '2337437'.
TestResults To Publish 12, Test run id:2337437
Test results publishing 12, remaining: 0. Test run id: 2337437
Published Test Run : .DevOpeProject/_TestManagement/Runs?runId=2337437&_a=runCharts
Async Command End: Publish test results
Finishing: Run tests
This pipeline runs everything through PowerShell, but from the log you can tell it executes dotnet.exe test in the end. I run the same command on my own PC (through cmd prompt with Admin permission), and could reproduce the issue, below is the output:
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BufferedStream.Flush()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.WriteAndFlushToChannel(String rawMessage) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs:line 413
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestSender.SendAfterTestRunEndAndGetResult(ITestMessageEventHandler runEventsHandler, Boolean isCancelled) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs:line 155
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.<>c__DisplayClass20_0.<AfterTestRunEnd>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 155
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 288
Results File: C:\temp\myName_myPcName_2025-03-31_15_23_42.trx
My.Project.UnitTests test failed with 1 error(s) (6.5s)
C:\Program Files\dotnet\sdk\9.0.200\Microsoft.TestPlatform.targets(48,5): error MSB6006: "dotnet.exe" exited with code 1.
Test summary: total: 12, failed: 0, succeeded: 12, skipped: 0, duration: 6.5s
Build failed with 1 error(s) in 10.3s
Below is the summary of my observations:
- This issue occurs to quite a number of our unit test projects, and they are the unit test of different types of .NET project, including web app, Azure Function app, and class library.
- It's intermittent. It happens quite often, but not always, occasionally it works OK.
- When testing on my own PC, right after a reboot, the test runs successfully, but from the 2nd attempt onwards, it starts failing, until I reboot my PC again, then it works again for the very first time, and start failing from the 2nd try again onwards... This might explain why it works some time in Azure.
- The version of Microsoft.NET.Test.Sdk matters, if I go back to 17.11.0 or lower versions, the issue disappears.
- I raised a support ticket against Microsoft, and they advised me to capture all the system logs with a tool when running the test, according to the log, the socket connection in relation to this error is a network call that looping back to localhost (127.0.0.1), but we don't know more details.
- Please note, this issue has nothing to do with the testing code itself, for all the test cases pass.
- I failed to reproduce the issue on my colleague's PC, because it always ran OK, which implies it is environmental, and my PC shares the environmental factor with almost all of our Azure build agents, which is still unknown to us atm.