System.TypeLoadException in Xamarin while calling web api

Getting this error

System.TypeLoadException: Could not load type 'System.Net.Http.FormattingUtilities' from assembly 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
}

    private async void btnGetQuote_onClicked(object sender, EventArgs e)
    {
        try
        {
            HttpClient cons = new HttpClient();
            cons.BaseAddress = new Uri("http://192.168.1.41:8020/");
            cons.DefaultRequestHeaders.Accept.Clear();
            cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            await MyAPIGet(cons);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public async Task MyAPIGet(HttpClient cons)
    {
        try
        {
            using (cons)
            {
                HttpResponseMessage res = await cons.GetAsync("api/Employees"); **// Error on this line.**

                res.EnsureSuccessStatusCode();

                if (res.IsSuccessStatusCode)
                {
                    var employee = await res.Content.ReadAsAsync<EmployeeModel>();
                    lblQuote.Text = employee.Name;
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

Please do the needful help.. thanks in advance.

Sign In or Register to comment.