[btls] Capture inner exception in MobileAuthenticatedStream
[mono.git] / mcs / class / System / Mono.Net.Security / MobileAuthenticatedStream.cs
index cf1082618e625432d5df952fbbe10d769f8591b5..8ca8fb6575455eefcd1ce6e67d3adb46d0e75b8c 100644 (file)
@@ -23,6 +23,7 @@ using System.IO;
 using System.Net;
 using System.Net.Security;
 using System.Globalization;
+using System.Runtime.ExceptionServices;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Security.Cryptography.X509Certificates;
@@ -214,7 +215,7 @@ namespace Mono.Net.Security
                                try {
                                        asyncRequest.StartOperation (ProcessHandshake);
                                } catch (Exception ex) {
-                                       throw SetException (ex);
+                                       ExceptionDispatchInfo.Capture (SetException (ex)).Throw ();
                                }
                        } finally {
                                if (lazyResult == null || lastException != null) {
@@ -241,7 +242,7 @@ namespace Mono.Net.Security
 
                        var e = lazyResult.Result as Exception;
                        if (e != null)
-                               throw SetException (e);
+                               ExceptionDispatchInfo.Capture (SetException (e)).Throw ();
                }
 
                internal void ValidateCreateContext (bool serverMode, string targetHost, SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)