diff --git a/src/Discord.Net/DiscordDataSocket.cs b/src/Discord.Net/DiscordDataSocket.cs index 822264cdd..d2d40604e 100644 --- a/src/Discord.Net/DiscordDataSocket.cs +++ b/src/Discord.Net/DiscordDataSocket.cs @@ -42,7 +42,7 @@ namespace Discord } catch (OperationCanceledException) { - throw _disconnectReason;// ?? new Exception("Operation was cancelled"); + _disconnectReason.Throw(); } try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler catch (OperationCanceledException) { return; } diff --git a/src/Discord.Net/DiscordVoiceSocket.cs b/src/Discord.Net/DiscordVoiceSocket.cs index 102e1dd3c..37892316f 100644 --- a/src/Discord.Net/DiscordVoiceSocket.cs +++ b/src/Discord.Net/DiscordVoiceSocket.cs @@ -109,7 +109,7 @@ namespace Discord } catch (OperationCanceledException) { - throw _disconnectReason; + _disconnectReason.Throw(); } SetConnected(); diff --git a/src/Discord.Net/DiscordWebSocket.cs b/src/Discord.Net/DiscordWebSocket.cs index 2b5b3eacf..4ca1bb6f8 100644 --- a/src/Discord.Net/DiscordWebSocket.cs +++ b/src/Discord.Net/DiscordWebSocket.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; using System.ComponentModel; using System.Net.WebSockets; +using System.Runtime.ExceptionServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -23,7 +24,7 @@ namespace Discord protected CancellationTokenSource _disconnectToken; protected string _host; protected int _timeout, _heartbeatInterval; - protected Exception _disconnectReason; + protected ExceptionDispatchInfo _disconnectReason; private ClientWebSocket _webSocket; private DateTime _lastHeartbeat; private Task _task; @@ -103,7 +104,7 @@ namespace Discord if (_disconnectReason == null) { _wasDisconnectUnexpected = isUnexpected; - _disconnectReason = ex; + _disconnectReason = ExceptionDispatchInfo.Capture(ex); _disconnectToken.Cancel(); } }