我正在尝试运行这段代码:
GetRepsButton.Command = new Command(async () =>
{
var url = @"https://url";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//crashes here
var test = await client.GetStringAsync(url);
});
Run Code Online (Sandbox Code Playgroud)
当我这样做时,整个应用程序崩溃并且输出窗口显示此错误:
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 …Run Code Online (Sandbox Code Playgroud) 这是我的场景。我构建了 xamarin 表单应用程序。当用户设备语言是英语时,它工作正常......但在阿拉伯语中。他打开的任何包含 DatePicker 或 datetime 的页面都会导致应用程序崩溃。请提供任何帮助。
我正在开发一个 Xamarin.Forms (4.1.0) 应用程序,它进行 REST 调用。
调用我的 Web 服务时,应用程序崩溃,无一例外。
仅在输出中收到此消息:
07-08 19:09:04.792 F/ (22723): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/mono/mini/debugger-agent.c:4387, condition `is_ok (error)' not met, function:get_this_async_id, Could not execute the method because the containing type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[RestQueryResultT_REF]', is not fully instantiated. assembly:<unknown assembly> type:<unknown type> member:(null)
07-08 19:09:04.793 F/libc (22723): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 22723 (io.puffix), pid 22723 (io.puffix)
Run Code Online (Sandbox Code Playgroud)
这是代码:
RestQueryResultT queryResult;
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(serviceUri))
{
string result = …Run Code Online (Sandbox Code Playgroud)