Internet Connectivity Issue

kenneth.leekenneth.lee USMember ✭✭✭
edited November 2016 in Xamarin.Forms

I came across this weird issue on Xamarin forms regarding internet access. In case number 1, where my App would startup with internet access and I will be able to log in and if my App loses internet connectivity via manually turning it off or just bad connectivity it will continue to work if the internet connectivity gets better. However in case number 2 If I start the App be it with internet connectivity or not but if my first internet call being...

            using (var httpClient = new HttpClient(new NativeMessageHandler()))
            {
                var result = httpClient.GetStringAsync("someurl");
                json = JObject.Parse(result.Result);
            }

...fails due to completely not having access and not just 100% packet loss it will continue to fail irregardless of if my internet connectivity is back to normal.

In case number 2 the Exceptions i'm getting is a System.Net.WebException: Error: NameResolutionFailure

I already have internet permissions enabled in the android manifest and I am not able to replicated this problem yet on iOS as im only able to simulate 100% loss on the emulator and i don't have a iOS device to test on.

Just want to put this out there and see if anyone can shed some light on this issue.

Answers

  • I have the exact same issue, and can be reproduced every single time, both on iOS and on Android. On Windows UWP it works fine:

    • Launch app in airplane mode
    • Try network access -> Fails (as expected)
    • Disable airplane mode and wait for 10 seconds (until IP address is assigned etc.)
    • Try network access -> Fails with NameResolutionFailure
    • Network access is impossible at this point. Any attempt to use HttpClient results in NameResolutionFailure

    However, when task-switching to another app and immediately come back, everything starts working again.

  • kenneth.leekenneth.lee USMember ✭✭✭

    Just an update. Its still a problem for me, the occurence of this problem doesn't come up at all during testing to be an immediate issue but I would like to find an elegant solution to feel confident pushing my app out to the public.

    If popping it to the background and back fixes this, we might be able to simulate the effects of that elegantly or figure out why doing so fixes it. I'm busy with other things right now but when i get to this I will update here.

  • kenneth.leekenneth.lee USMember ✭✭✭

    Ah I saw your post and got excited i just had to stop what i was doing to test this out for myself and it worked! Thanks for referring me to this workaround @PhilippeLeybaert . Works like a charm!

  • kenneth.leekenneth.lee USMember ✭✭✭

    I copied and paste the stacktrace if anyone would like to take a look

    11-24 16:54:24.541 E/mono-rt ( 4257): [ERROR] FATAL UNHANDLED EXCEPTION: System.AggregateException: One or more errors occurred. ---> System.Net.WebException: Error: NameResolutionFailure
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in :0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown ---
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0041e] in <188a9a4ce4444355b31a56f673d16ed4>:0 11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown --- 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClient+c__async0.MoveNext () [0x000f3] in <188a9a4ce4444355b31a56f673d16ed4>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown ---
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClient+<GetStringAsync>c__async5.MoveNext () [0x0007d] in <188a9a4ce4444355b31a56f673d16ed4>:0 11-24 16:54:24.541 E/mono-rt ( 4257): --- End of inner exception stack trace --- 11-24 16:54:24.541 E/mono-rt ( 4257): ---> (Inner Exception #0) System.Net.WebException: Error: NameResolutionFailure 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in <fddd019cf34a490fbe2a9ca87db0c629>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception w

  • kenneth.leekenneth.lee USMember ✭✭✭

    I copied and paste the stacktrace if anyone would like to take a look

    11-24 16:54:24.541 E/mono-rt ( 4257): [ERROR] FATAL UNHANDLED EXCEPTION: System.AggregateException: One or more errors occurred. ---> System.Net.WebException: Error: NameResolutionFailure
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in :0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown ---
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0041e] in <188a9a4ce4444355b31a56f673d16ed4>:0 11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown --- 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClient+c__async0.MoveNext () [0x000f3] in <188a9a4ce4444355b31a56f673d16ed4>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception was thrown ---
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <785034112d7d481c85045a3ca28142be>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.Http.HttpClient+<GetStringAsync>c__async5.MoveNext () [0x0007d] in <188a9a4ce4444355b31a56f673d16ed4>:0 11-24 16:54:24.541 E/mono-rt ( 4257): --- End of inner exception stack trace --- 11-24 16:54:24.541 E/mono-rt ( 4257): ---> (Inner Exception #0) System.Net.WebException: Error: NameResolutionFailure 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in <fddd019cf34a490fbe2a9ca87db0c629>:0 11-24 16:54:24.541 E/mono-rt ( 4257): at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in <785034112d7d481c85045a3ca28142be>:0
    11-24 16:54:24.541 E/mono-rt ( 4257): --- End of stack trace from previous location where exception w

Sign In or Register to comment.