0

I am working on a Xamarin.Forms PCL project which uses web requests to log users in. It has been working fine since I created the app a couple months ago but suddenly today it stopped working and I haven't changed anything in the login code.

The web request is ran with

var values = new Dictionary<string, string>
{
    {"username", username },
    {"password", password }
};

var content = new FormUrlEncodedContent(values);
var response = await App.client.PostAsync(App.URL + "account.php", content);
var responseString = await response.Content.ReadAsStringAsync();
string page_result = responseString;

It goes into break mode and says

System.Threading.Tasks.TaskCanceledException: A task was canceled.

When I push the button that runs the web request the output says

03-24 21:29:44.062 E/mono ( 9248): Unhandled Exception: 03-24 21:29:44.062 E/mono ( 9248): System.Threading.Tasks.TaskCanceledException: A task was canceled. 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00026] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Net.Http.HttpClientHandler+d__64.MoveNext () [0x004f5] in :0 03-24 21:29:44.062 E/mono ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Net.Http.HttpClient+d__49.MoveNext () [0x000ca] in :0 03-24 21:29:44.062 E/mono ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.062 E/mono ( 9248): at SocialNetwork.LoginPage+d__2.MoveNext () [0x000a1] in C:\Users\Jacob\OneDrive\Documents\Visual Studio\SocialMedia\SocialNetwork\SocialNetwork\LoginPage.xaml.cs:36 03-24 21:29:44.062 E/mono ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.062 E/mono ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in :0 03-24 21:29:44.062 E/mono ( 9248): at SocialNetwork.LoginPage+d__1.MoveNext () [0x0002c] in C:\Users\Jacob\OneDrive\Documents\Visual Studio\SocialMedia\SocialNetwork\SocialNetwork\LoginPage.xaml.cs:23 03-24 21:29:44.062 E/mono ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.062 E/mono ( 9248): at (wrapper dynamic-method) System.Object.b3fe65b9-9c99-495b-aeb4-4948b63ae737(intptr,intptr) 03-24 21:29:44.082 E/mono-rt ( 9248): [ERROR] FATAL UNHANDLED EXCEPTION: System.Threading.Tasks.TaskCanceledException: A task was canceled. 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00026] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Net.Http.HttpClientHandler+d__64.MoveNext () [0x004f5] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Net.Http.HttpClient+d__49.MoveNext () [0x000ca] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at SocialNetwork.LoginPage+d__2.MoveNext () [0x000a1] in C:\Users\Jacob\OneDrive\Documents\Visual Studio\SocialMedia\SocialNetwork\SocialNetwork\LoginPage.xaml.cs:36 03-24 21:29:44.082 E/mono-rt ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in :0 03-24 21:29:44.082 E/mono-rt ( 9248): at SocialNetwork.LoginPage+d__1.MoveNext () [0x0002c] in C:\Users\Jacob\OneDrive\Documents\Visual Studio\SocialMedia\SocialNetwork\SocialNetwork\LoginPage.xaml.cs:23 03-24 21:29:44.082 E/mono-rt ( 9248): --- End of stack trace from previous location where exception was thrown --- 03-24 21:29:44.082 E/mono-rt ( 9248): at (wrapper dynamic-method) System.Object.b3fe65b9-9c99-495b-aeb4-4948b63ae737(intptr,intptr)

Dan
  • 1,100
  • 2
  • 13
  • 36
  • https://stackoverflow.com/questions/29179848/httpclient-a-task-was-cancelled – Venson Mar 25 '18 at 04:36
  • Possible duplicate of [HttpClient - A task was cancelled?](https://stackoverflow.com/questions/29179848/httpclient-a-task-was-cancelled) – Venson Mar 25 '18 at 04:37
  • When something suddenly changes - delete bin obj folders for all platforms and rebuild. – Nick Kovalsky Mar 25 '18 at 05:19
  • @JPVenson I tried looking at that post but didn't seem to have a fix to my problem – Dan Mar 25 '18 at 06:42
  • @NickKovalsky I tried deleting all the bin and obj but didn't fix it – Dan Mar 25 '18 at 07:00
  • 1
    I forgot the details but i had similar issue.. was due to fact httpserver was included/referenced in some nuget packages, and when i changed/upgraded some packaged it had duplicated and caused issues. so i removed one package i didnt need and it went ok. – Nick Kovalsky Mar 25 '18 at 07:34
  • 1
    Did you check if your backend is still working and that your testdevice / simulator / emulator has internet acess? – Andre Kraemer Mar 25 '18 at 14:16

1 Answers1

0

The issue was on my backend.

I tried connecting to my database in the browser directly and realised the login was updated.

Dan
  • 1,100
  • 2
  • 13
  • 36