I've created an android application using Xamarin.android that consumes an asmx webservice.the latter connects my app to sql server. the app works perfectly with good internet connection. but when I have bad internet service, I get an exception in visual studio (while deploying my app to a physical device). the exception is: System.Reflection.TargetInvocationException. and when my phone is not connected to my laptop and I run the app with poor connection, my phone gets out from the app. I am trying to catch this exception so that the app doesn't crash and at least give me an alert dialog that my connection failed so I did this:
WSitems.WebService1 ws = new WSitems.WebService1();
try
{
ws.itemsinfoAsync();
ws.itemsinfoCompleted += Ws_itemsinfoCompleted;
}
catch(Exception exp )
{
Context context = this.Context;
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.SetTitle("Connection to Server failed");
alert.SetMessage("Please, check your internet connection!");
alert.SetPositiveButton("okay",( senderAlert, args) => {
alert.Dispose();
});
_dialog = alert.Create();
_dialog.Show();
}
but the problem wasn't solved. what should I do? thanks in advance.