vstest.console.exe error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

2.7k views Asked by At

I have ran my test project from Test Explorer in Visual Studio 2022 and fortunately all tests passed. On the other side I'm trying to use vstest.console.exe to run MyProject.Tests.build.appxrecipe file but it's failing.

The log is the following:

The active test run was aborted. Reason: Unable to communicate with test host process.
Closing app with package full name 'b99a209c-7a2d-42fa-ba34-b16c8dee0379_1.0.0.0_x64__amhbm8v6a514r'.

Test Run Aborted with error System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.Stream.ReadByte()
   at System.IO.BinaryReader.ReadByte()
   at System.IO.BinaryReader.Read7BitEncodedInt()
   at System.IO.BinaryReader.ReadString()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---.
Total tests: Unknown
     Passed: 152
 Total time: 29.0509 Seconds

Something similar to this GitHub issue.

1

There are 1 answers

0
rlm96 On

I just fixed this issue upgrading two package refereces (MSTest.TestAdapter and MSTest.TestFramework) from 2.1.1 version to 2.2.8.