I created a .net 4.7 web api project with a simple Action that returns a string
[System.Web.Http.Route("api/GetData")]
[System.Web.Http.HttpGet]
public async Task<System.Net.Http.HttpResponseMessage> GetData()
{
string result = await Task.FromResult("test data");
var content = new System.Net.Http.StringContent(result);
return new System.Net.Http.HttpResponseMessage() { Content = content };
}
When querying this route I get a result of "test data". As soon as I add a NetStandard 2.0 package ("System.Threading.Tasks.Extensions" for example) and re-query the route my result looks completely different
{
"Version": {
"_Major": 1,
"_Minor": 1,
"_Build": -1,
"_Revision": -1
},
"Content": {
"Headers": [{
"Key": "Content-Type",
"Value": ["text/plain; charset=utf-8"]
}]
},
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": [],
"RequestMessage": null,
"IsSuccessStatusCode": true
}
The strange thing is before the NuGet reference System.Net.Http is v4.0.0.0 Location "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7\System.Net.Http.dll" after I add the reference the version changes to v4.2.0.0 location "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll"
Does anyone have any ideas why this is and how to fix it?