Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurthurb <35814204+Gurthurb@users.noreply.github.com>2020-12-28 00:21:03 +0300
committerGurthurb <35814204+Gurthurb@users.noreply.github.com>2020-12-28 00:21:03 +0300
commit763ae5cb68303595c1bb1fb0133a03d52634a9ac (patch)
tree3b9fff192f433d535e88b016d76e19fd1e417b74 /Duplicati/Library
parentd2189933e8dfa936efd4ee3044206f150339efec (diff)
Avoid NullReferenceException if an IAsyncResult or WebRequest doesn't contain a WebResponse property
An example of when this happens is when shutting down TrayIcon (using its context menu), at least on Windows. This is quite annoying when debugging with Visual Studio (having the default exception settings).
Diffstat (limited to 'Duplicati/Library')
-rw-r--r--Duplicati/Library/Utility/AsyncHttpRequest.cs4
1 files changed, 2 insertions, 2 deletions
diff --git a/Duplicati/Library/Utility/AsyncHttpRequest.cs b/Duplicati/Library/Utility/AsyncHttpRequest.cs
index 7a276230a..0ba349d71 100644
--- a/Duplicati/Library/Utility/AsyncHttpRequest.cs
+++ b/Duplicati/Library/Utility/AsyncHttpRequest.cs
@@ -230,11 +230,11 @@ namespace Duplicati.Library.Utility
{
WebResponse resp = null;
- try { resp = (WebResponse)r.GetType().GetProperty("Response", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(r); }
+ try { resp = r.GetType().GetProperty("Response", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.GetValue(r) as WebResponse; }
catch {}
if (resp == null)
- try { resp = (WebResponse)m_owner.m_request.GetType().GetField("webResponse", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(m_owner.m_request); }
+ try { resp = m_owner.m_request.GetType().GetField("webResponse", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.GetValue(m_owner.m_request) as WebResponse; }
catch { }
if (resp != null)