1
votes

I'm using Web API 5, it's has been working fine, I return a HttpResponseMessage object with Content = new StringContent("content here") and get the expected content when calling the API.

[HttpPost]
    public async Task<HttpResponseMessage> GetData([FromBody]DataObject input)
    {
      .....
      return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(returnModel))
            };
    }

However, I recently updated a number of MVC and .NET NuGet packages, and now, while the project compiles and runs fine locally, when I deploy to an Azure Web App, calling the API returns the actual HttpResponseMessage object with no content, rather than the content:

{
"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
}

Normally this same call would return a JSON string of the Content object. Is there some odd dependency issue happening, any ideas on how to fix without rolling back all of the nuget updates? Or do I need to update a setting on the Azure Web App (already have .NET 4.7 set).

1
Were you able to nail this down at all? Ran into the same problem yesterday. Your question got me thinking. It turned out that installing Polly nuget package did this to all my HttpResponseMessage return values. - Douglas Anderson
Unfortunately not - we basically had to roll all of our Nuget packages back to before updating :( spent too much time already, so wasn't able to upgrade package by package and figure out what was the issue. If you figure it out, let me know! - codechinchilla

1 Answers

0
votes

Well assuming an ApiController, the action can be refactored to use the more recent advised syntax.

[HttpPost]
public async Task<IHttpActionResult> GetData([FromBody]DataObject input) {

    //.....code awaited here and gets 'returnModel'

    return Ok(returnModel);
}