Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public string Execute(string url, DataSet dsItem)
    {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));

                    DataRow gXITEMrow = dsItem.Tables[0].Rows[0];

                    GXITEM gXITEM = new GXITEM();

                    gXITEM.GXID = new Guid();
                    if (gXITEMrow["GXREVNUM"]!=DBNull.Value)
                        gXITEM.GXREVNUM = Convert.ToInt32(gXITEMrow["GXREVNUM"]);
                    if (gXITEMrow["GXCODE"] != DBNull.Value)
                        gXITEM.GXCODE = Convert.ToString(gXITEMrow["GXCODE"]);
                    var postTask = client.PostAsJsonAsync<GXITEM>("api/GXITEMs/gXITEM", gXITEM);

                    postTask.Wait();
                    var result = postTask.Result;
                }
    }


This is my client code trying to call my WebApi using am HttpClient
My problem is that I get a runtime error when I am calling the API: could not load file or assembly system.net.http.formatting 5.2.7.0 although the specified assembly is referenced in my client project.I have added the NuGet package Microsoft.AspNet.WebApi.Client 5.2.7. What can be wrong?

What I have tried:

uninstalled and installed the nugget package
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900