title: UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread
body: <p>I'm trying to run this code:</p>
  
  <pre><code>GetRepsButton.Command = new Command(async () =&gt;
              {
                  var url = @"https://url";
  
                  HttpClient client = new HttpClient();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
                  //crashes here
                  var test = await client.GetStringAsync(url);
              });
  </code></pre>
  
  <p>And when I do, the entire app crashes and the output window shows this error:</p>
  
  <pre><code>ROR: +[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 
  Resolved pending breakpoint at 'SelectRep.xaml.cs:110,1' to void NameSpace.&lt;ClientPicker_SelectedIndexChanged1&gt;d__3.MoveNext () [0x0000c].
  </code></pre>
  
  <p>Although I dont think I should have to since i'm not doing anything with the UI, I have tried <code>InvokeOnMainThread</code> which does not work. I've also tried changing to .Result instead of await, and I've tried <code>GetAsync</code> and reading the content, along with using <code>WebClient</code> instead of <code>HttpClient</code>. All cause this same error.</p>
  
  <p>Any ideas? I'm using Xamarin forms 4 pre 7.</p>