I am running a .NET Standard 2 project. I have added the Microsoft.AspNet.WebApi.Client (5.2.7) package. My call to HttpClient.GetAsync are working fine, but as soon as I try HttpClient.PostAsync, HttpClient.PostAsJsonAsync (or event the PutAsync versions), this error is thrown:
Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
I call the method like this:
private async Task<T> Add<T>(string path, T item) where T : class
{
try
{
return await _httpClientService
.Add(path, item)
.ConfigureAwait(false);
}
catch (Exception ex) //the exception is thrown here
{
throw ex;
}
}
//and this is the service
public async Task<T> Add<T>(string path, T item)
{
if (string.IsNullOrEmpty(baseUrl))
{
return default(T);
}
T result = default;
try
{
SetAuthorizationHeader(httpClient);
var response = await httpClient.PutAsync(path, item, new JsonMediaTypeFormatter()).ConfigureAwait(false); //without this line, the function is called. When this line is included, this method does not get called
//response.EnsureSuccessStatusCode();
//await response.Content.ReadAsStringAsync().ContinueWith((Task<string> x) =>
//{
// if (x.IsFaulted)
// {
// this._loggingService.Fatal($"{nameof(Add)} failed");
// throw x.Exception;
// }
// result = JsonConvert.DeserializeObject<T>(x.Result);
//});
}
catch (Exception ex)
{
throw ex;
}
return result;
}