Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I reference HttpClient for dnx451 and dnxcore50?

How should I reference HttpClient using a project.json file?
I want both frameworks to work: dnx451 and dnxcore50.

Here is my current attempt at the project.json file. (I've removed the irrelevant parts.)

{
  "dependencies": {
    "Microsoft.Net.Http": "2.2.29",
    "Microsoft.Net.Http.Headers": "1.0.0-beta4",
    "System.Net.Http": "4.0.0-beta-22816"
  },
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.Net.Http": "4.0.0.0"
      }
    },
    "dnxcore50": { }
  }
}

Discovering the dependencies I do have listed was a trial-and-error procedure.

With this project.json file, the dnxcore50 context properly resolves all the classes in this example block of code, but it fails to resolve HttpRequestMessage, HttpMethod, and MediaTypeWithQualityHeaderValue with the dnx451 context:

var request = new HttpRequestMessage(HttpMethod.Get, "...");
request.Headers.Accept.Clear();
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/..."));
var response = await client.SendAsync(request);
var model = await response.EnsureSuccessStatusCode().Content.ReadAsAsync<SomeModel>();
like image 362
Timothy Shields Avatar asked Jun 12 '15 00:06

Timothy Shields


1 Answers

As of the time of posting (June 11, 2015) this is the combination that worked for me for both dnx451 and dnxcore50.

{
  "dependencies": {
    "Microsoft.AspNet.WebApi.Client": "5.2.3"
  },
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.Net.Http": "4.0.0.0"
      }
    },
    "dnxcore50": {
      "dependencies": {
        "System.Net.Http": "4.0.0-beta-22816"
      }
    }
  }
}
like image 184
Timothy Shields Avatar answered Oct 31 '22 22:10

Timothy Shields