Skip to content

AndroidHttpClient crashes  #2498

Closed
Closed

Description

@virsanna

I have a Xamarin.Forms project, where data is given to the user through the network.
In case when the phone is connected to the router through Wi-Fi, but router itself is disconnected from the network Xamarin.Essentials Connectivity gives the documented false status of connection, and so, expected behavior of the app is to fall due to timeout (that could be caught and processed to give the appropriate info to the user).
Though, this expected behavior is observed on iOS and on Android emulator on VS 2017, but not on the real Android device (the app hangs and then crashes there). There is a solution in SO for this problem:
https://stackoverflow.com/questions/48475378/httpclient-not-working-on-android
If I change the properties of the Android project as it is said, I have another problem. In certain cases our server responds with redirect, and I hoped that it was the same issue as that: #1923
(it is solved with #2390)
I have updated the Android SDK with the last stable version yesterday, but my app still crashes.

Error message:
Unable to convert instance of type 'Java.Net.URLConnectionInvoker' to type 'Java.Net.HttpURLConnection'.

StackTrace:
at Java.Interop.JavaObjectExtensions.CastClass (Android.Runtime.IJavaObject instance, System.Type resultType) [0x00042] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs:80
at Java.Interop.JavaObjectExtensions._JavaCast[TResult] (Android.Runtime.IJavaObject instance) [0x0002f] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs:63
at Java.Interop.JavaObjectExtensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance) [0x00000] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs:50
at Android.Runtime.Extensions.JavaCast[TResult] (Android.Runtime.IJavaObject instance) [0x00000] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Android.Runtime/Extensions.cs:11
at Xamarin.Android.Net.AndroidClientHandler.SetupRequestInternal (System.Net.Http.HttpRequestMessage request, Java.Net.URLConnection conn) [0x00027] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:763
at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x001ec] in /Users/builder/data/lanes/1196/c72abb69/source/monodroid/external/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:280
at System.Net.Http.HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x00080] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276
[and then go the methods from my project]

Environment:
Microsoft Visual Studio Community 2017
Version 15.9.3
VisualStudio.15.Release/15.9.3+28307.145
Microsoft .NET Framework
Version 4.7.03056

Xamarin 4.12.3.73 (d15-9@20b35b881)

Xamarin.Android SDK 9.1.199.31 (HEAD/c72abb69c)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: mono/mono@b63e5378e38
Java.Interop: xamarin/java.interop/master@6dd6f16
LibZipSharp: grendello/LibZipSharp/master@d695149
LibZip: nih-at/libzip@b95cf3f
MXE: xamarin/mxe@b9cbb535
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@4ea4c69
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9e78d6e

default

Activity

  1. changed the title [-]AndroidHttpClient crashes on real device[/-] [+]AndroidHttpClient crashes [/+] on Dec 6, 2018
  2. added
    bugComponent does not function as intended.
    on Dec 7, 2018
  3. jeremyVignelles commented on Dec 7, 2018

    @jeremyVignelles

    Duplicate of #1945 ?

  4. grendello commented on Dec 10, 2018

    @grendello
    Contributor

    @virsanna the fix you indicated in your report is correct for your issue. However, the fix hasn't been released in stable Xamarin.Android, thus the update to the latest stable didn't have any effect for you. The fix is going to be part of the next 15.9 update as well as the upcoming 16.0 release. I'm going to close this issue, but please reopen it should the problem persist after you update to one of the aforementioned releases when they're released, thanks!

  5. virsanna commented on Dec 10, 2018

    @virsanna
    Author

    @grendello But I have now 15.9.3. Do you mean 15.9.4?

  6. ghost locked as resolved and limited conversation to collaborators on Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugComponent does not function as intended.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions