Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

iOS HttpClient crash

$
0
0
HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var jsonstring = await client.GetStringAsync("https://asdasdadasd" + url);

Causes this error:

2019-03-29 11:18:43.901 Eliant.App.iOS[3859:3548233] [AppCenterCrashes] ERROR: +[MSWrapperLogger MSWrapperLog:tag:level:]/7 Unhandled Exception:
UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
at UIKit.UIApplication.EnsureUIThread () [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.16/src/Xamarin.iOS/UIKit/UIApplication.cs:89
at UIKit.UIGestureRecognizer.RemoveTarget (Foundation.NSObject target, System.IntPtr action) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.16/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:342
at UIKit.UIGestureRecognizer.OnDispose () [0x00016] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.16/src/Xamarin.iOS/UIKit/UIGestureRecognizer.cs:41
at UIKit.UIGestureRecognizer.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.16/src/Xamarin.iOS/UIKit/UIGestureRecognizer.g.cs:959
at
Foundation.NSObject.Finalize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.6.0.16/src/Xamarin.iOS/Foundation/NSObject2.cs:143

Any ideas?

Commenting out await client.GetStringAsync() makes the app work fine. I've tried running it using Device invoke on main thread (even though i dont think there is any reason i should need to do that?) i've tried .result instead of await, and i've tried getasync().content.readstringasync and always have the same issue.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>