2

I have copied the exception below. I have connected my Android device through VPN , If VPN connection failed then the FlurlHttp call is giving unhandled exception. I am developing application on Xamarin.Android. If device is connected through VPN then it's working fine. Please some one give some solution, how to handle it. How to get response StatusCode (200) using Flurl Http call ?

Flurl.Http.FlurlHttpException: Request to http://192.168.110.60/TestServices/MyCall.aspx?method=Test&username=abc&password=abc failed. A task was canceled. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
   --- End of inner exception stack trace ---
  at Flurl.Http.Configuration.FlurlMessageHandler+<SendAsync>d__1.MoveNext () [0x00000] in C:\projects\flurl\src\Flurl.Http.Shared\Testing\HttpCallAssertion.cs:192 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00042] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 
  at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess (System.Threading.Tasks.Task task) [0x0001c] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 
  at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00009] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 
  at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 
  at Flurl.Http.HttpResponseMessageExtensions+<ReceiveString>d__3.MoveNext () [0x00000] in C:\projects\flurl\src\Flurl.Http.Shared\Testing\HttpCallAssertion.cs:150 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <abd9ee18f6114b4cae6c0d74712f64b5>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <abd9ee18f6114b4cae6c0d74712f64b5>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <abd9ee18f6114b4cae6c0d74712f64b5>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <abd9ee18f6114b4cae6c0d74712f64b5>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <abd9ee18f6114b4cae6c0d74712f64b5>:0 
  at PCLTest.APIRepository.APIRepo+<ValidateUrl>d__0.MoveNext () [0x0004f] in C:\D-Drive\branches\PCLTest\APIRepository\APIRepo.cs:20 
An unhandled exception occured.
Faiz Anwar
  • 658
  • 2
  • 9
  • 18

1 Answers1

1

The request is not completing. TaskCanceledException means either it was canceled explicitly (via a CancelationToken) or, more likely, a timeout occurred. Does it spin for a while before the exception is thrown? Even more likely it's a timeout. Flurl's default timeout is 100 seconds, but you can configure it to something else.

Also, I would highly recommend that you upgrade Flurl.Http if possible. You are using a very old version.

Todd Menier
  • 37,557
  • 17
  • 150
  • 173
  • Thanks for your quick reply. I am using using Flurl.Http.Signed latest version-1.1.2 which only available on NuGet package Manager. When server is unavailable due to VPN disconnection then only unhandled exception occours. I need only how to handle it without any crash. – Faiz Anwar May 23 '18 at 17:44
  • **This is my code where I am getting Exception** -------------------------------------------------------------------------------------- `public async Task GetData() { try { var getResp = await "http://192.168.110.60/TestServices/MyCall.aspx?method=Test&username=abc&password=abc".GetStringAsync(); return getResp; } catch (Exception ex) { return null; } }` – Faiz Anwar May 23 '18 at 17:44
  • An exception thrown in your try block isn't caught in your catch block? If that's the case, I'm afraid I don't know the answer. Sorry. – Todd Menier May 23 '18 at 19:35
  • If VPN disconnected then the URL will be treated as invalid URL. How to handle TaskCanceledException if internet connectivity lost in between the Http call. Please advise – Faiz Anwar May 24 '18 at 05:52
  • If VPN not connected then on browser if I request the same URL then I got `This site can’t be reached 192.168.110.60 took too long to respond. ERR_CONNECTION_TIMED_OUT` – Faiz Anwar May 25 '18 at 07:16