Skip to content

AndroidHttpClient crashes  #2498

Closed
Closed
@virsanna

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

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