首页 > 解决方案 > 活动的测试运行已中止。System.Reflection.TargetInvocationException

问题描述

在运行测试方法时遇到以下问题,但并非总是如此。一旦我遇到这个问题,我就无法进一步运行任何其他测试方法。

The active Tests Run was aborted.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.BufferedStream.WriteByte(Byte value)
   at System.IO.BinaryWriter.Write(Byte value)
   at System.IO.BinaryWriter.Write7BitEncodedInt(Int32 value)
   at System.IO.BinaryWriter.Write(String value)
   at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.WriteAndFlushToChannel(String rawMessage)
   at M

    icrosoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.SendMessage(String messageType)
       at Microsoft.TestPlatform.VsTestConsole.TranslationLayer.VsTestConsoleRequestSender.AbortTestRun()
       at Microsoft.TestPlatform.VsTestConsole.TranslationLayer.VsTestConsoleWrapper.AbortTestRun() at Microsoft.VisualStudio.TestWindow.TestPlatformV2.ProxyRunRequest.Abort()
       at Microsoft.VisualStudio.TestWindow.TestPlatformV2.ProxyRunRequest.Dispose()
       at Microsoft.VisualStudio.TestWindow.Controller.Request.<RunRequests>d__95.MoveNext()
       --- End of inner exception stack trace ---
       at Microsoft.VisualStudio.TestWindow.Controller.Request.<ProcessRequest>d__94.MoveNext()
     ========== Run test finished: 0 run (0:00:00.0408906) ==========



    

Can i get any solution for this error other than upgrading to latest version of VS 2019. Currently I am using VS 2019 version 16.2.

标签: c#unit-testingabort

解决方案


推荐阅读