Wednesday, 19 December 2018

Xamarin & Android - crash on exiting from method

I don't know what can I tell more. I have this method:

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;
}

Nothing special. client.SendAsync(rm) is executed, response.StatusCode is Ok. Application just crashes when exiting from this method.

Output shows me just this assert:

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)

And nothing more. client is HttpClient. I have setting in my Android project: HttpClient Implementation set to Android.

Does anyone have any idea what could be wrong?

edit

SendAsyncRequest is used like that:

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));
}



from Xamarin & Android - crash on exiting from method

No comments:

Post a Comment