【发布时间】:2018-12-16 19:17:05
【问题描述】:
我不知道我还能说什么。 我有这个方法:
public async Task<HttpResponseMessage> SendAsyncRequest(string uri, string content, HttpMethod method, bool tryReauthorizeOn401 = true)
{
HttpRequestMessage rm = new HttpRequestMessage(method, uri);
if (!string.IsNullOrWhiteSpace(content))
rm.Content = new StringContent(content, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.SendAsync(rm);
if (response.StatusCode == HttpStatusCode.Unauthorized && tryReauthorizeOn401)
{
var res = await AuthenticateUser();
if(res.user == null)
return response;
return await SendAsyncRequest(uri, content, method, false);
}
return response;
}
没什么特别的。 client.SendAsync(rm) 被执行,response.StatusCode 是好的。 退出此方法时应用程序会崩溃。
输出只显示了这个断言:
12-16 20:09:22.025 F/ ( 1683): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mono/mini/debugger-agent.c:4957, condition `is_ok (error)' not met, function:set_set_notification_for_wait_completion_flag, Could not execute the method because the containing type is not fully instantiated. assembly:<unknown assembly> type:<unknown type> member:(null)
12-16 20:09:22.025 F/libc ( 1683): Fatal signal 6 (SIGABRT), code -6 in tid 1683 (omerang.Android)
仅此而已。 客户端是 HttpClient。 我在我的 Android 项目中有设置:HttpClient Implementation 设置为 Android。
有谁知道可能出了什么问题?
编辑
SendAsyncRequest 是这样使用的:
public async Task<(HttpResponseMessage response, IEnumerable<T> items)> GetListFromRequest<T>(string uri)
{
HttpResponseMessage response = await SendAsyncRequest(uri, null, HttpMethod.Get);
if (!response.IsSuccessStatusCode)
return (response, null);
string content = await response.Content.ReadAsStringAsync();
var items = JsonConvert.DeserializeObject<IEnumerable<T>>(content);
return (response, new List<T>(items));
}
【问题讨论】:
-
...containing type is not fully instantiated...你是如何使用 SendAsyncRequest 方法的?即,如果没有使用模式,我会假设您使用的是 Result 等,但这只是一个猜测。 -
看看我编辑的问题。
-
@AdamJachocki 不断向上移动调用堆栈,以确保您没有进行任何可能导致死锁的
.Result阻塞调用。 -
我没有。更重要的是,一切都在 WinForms 上运行(这个项目是 Winforms 和 Xamarin 的通用项目)。但在这里它只是崩溃,没有任何例外。调试器刚刚结束它的工作,VS 停止调试。
-
@AdamJachocki 好的,什么叫
GetListFromRequest,然后叫什么等等?显示可用于帮助重现和诊断问题的minimal reproducible example。也可能是火灾后忘记问题,但没有提供足够的详细信息来进行明确的评估。
标签: android xamarin crash httpclient