Preserve exception stack trace using ExceptionDispatchInfo

Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-03 21:23:55 +00:00
parent c33c9814c2
commit 04e0144004

View File

@@ -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
{