diff --git a/mRemoteNG/Connection/Protocol/VNC/Connection.Protocol.VNC.cs b/mRemoteNG/Connection/Protocol/VNC/Connection.Protocol.VNC.cs index 1c05686b..37ea2b7b 100644 --- a/mRemoteNG/Connection/Protocol/VNC/Connection.Protocol.VNC.cs +++ b/mRemoteNG/Connection/Protocol/VNC/Connection.Protocol.VNC.cs @@ -8,6 +8,7 @@ using mRemoteNG.UI.Forms; using mRemoteNG.Resources.Language; using System.Runtime.Versioning; using mRemoteNG.Security; +using System.Runtime.ExceptionServices; // ReSharper disable ArrangeAccessorOwnerBody @@ -22,7 +23,7 @@ namespace mRemoteNG.Connection.Protocol.VNC private VncSharpCore.RemoteDesktop _vnc; private ConnectionInfo _info; private static bool _isConnectionSuccessful; - private static Exception _socketexception; + private static ExceptionDispatchInfo _socketexception; private static readonly ManualResetEvent TimeoutObject = new(false); private static readonly object _testConnectLock = new(); @@ -176,7 +177,7 @@ namespace mRemoteNG.Connection.Protocol.VNC // Connection completed but failed - tcpclient will be closed in CallBackMethod's finally block if (_socketexception != null) { - throw _socketexception; + _socketexception.Throw(); } } else @@ -205,7 +206,7 @@ namespace mRemoteNG.Connection.Protocol.VNC catch (Exception ex) { _isConnectionSuccessful = false; - _socketexception = ex; + _socketexception = ExceptionDispatchInfo.Capture(ex); } finally {