From 4ce0f72d6d85bca0a94e68fc9248838bc298bdbd Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 28 Feb 2018 08:43:28 +0800 Subject: [PATCH] TelegramClient: move the _sender null check to RequestWithDcMigration() The method IsPhoneRegisteredAsync() was calling RequestWithDcMigration() which was the real method that made use of the _sender field, so we can move the null check to there. This will also help track down possible NullReferenceExceptions that could happen when other callers of this method arrive with a bad _sender, which might aid us trying to fix #706. --- TLSharp.Core/TelegramClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 0692486..0a7b070 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -111,6 +111,9 @@ namespace TLSharp.Core private async Task RequestWithDcMigration(TLMethod request) { + if (_sender == null) + throw new InvalidOperationException("Not connected!"); + var completed = false; while(!completed) { @@ -139,9 +142,6 @@ namespace TLSharp.Core if (String.IsNullOrWhiteSpace(phoneNumber)) throw new ArgumentNullException(nameof(phoneNumber)); - if (_sender == null) - throw new InvalidOperationException("Not connected!"); - var authCheckPhoneRequest = new TLRequestCheckPhone() { PhoneNumber = phoneNumber }; await RequestWithDcMigration(authCheckPhoneRequest);