Can the response to a PostAsJsonAsync post be NULL

Scott Thornton 1 Reputation point
2022-11-15T05:39:23.197+00:00

Hi,

Very occasionally, there will be a bug in my software that will result in a claim being sent to a government web service twice.

The first time the claim is sent there occurs an exception, and the transaction is rolled back. Later it will be sent again successfully. The government web site will have processed two claims.

Basically the code looks like this:

try {  
	  
	var response = await _httpClientManager.PostAsJsonAsync<ClaimRequest>(url, request, null);  
  
    return ResponseMessage(response);  
}  
catch (Exception e)  
{  
    return Content(HttpStatusCode.BadGateway, e);  
}  

The caught exception is logged and looks like:

     "Response" : {  
         "ClassName" : "System.ArgumentNullException",  
         "Message" : "Value cannot be null.",  
         "Data" : null,  
         "InnerException" : null,  
         "HelpURL" : null,  
         "StackTraceString" : "   at System.Web.Http.Results.ResponseMessageResult..ctor(HttpResponseMessage response)\r\n   at System.Web.Http.ApiController.ResponseMessage(HttpResponseMessage response)\r\n   at some private stuff removed from here .MoveNext() in C:\\......Controller.cs:line 92",  
         "RemoteStackTraceString" : null,  
         "RemoteStackIndex" : 0,  
         "ExceptionMethod" : "1\n.ctor\nSystem.Web.Http, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\nSystem.Web.Http.Results.ResponseMessageResult\nVoid .ctor(System.Net.Http.HttpResponseMessage)",  
         "HResult" : -2147467261,  
         "Source" : "System.Web.Http",  
         "WatsonBuckets" : null,  
         "ParamName" : "response"   
    }   

The exception refers to Line 92, which is

return ResponseMessage(response);  

It isn't my code, and I am very very new to this software, and using PostAsJsonAsync

Is the error saying the PostAsJsonAsync response didn't return anything ( NULL ), or is the response to the post "Value cannot be null" and the service is responding to the JSON I have sent ( something is incorrect with the JSON)?

I do not know if the government service is responding correctly to my post ( or at all), but they do process the JSON claim that I have sent which is the confusing thing.

( I have reached out to them, but who knows if they will acknowledge the issue ).

Thanks for any advice.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,026 Reputation points
    2022-11-15T15:49:45.943+00:00

    The error you are getting means the response did not properly parse into your object. You will need to look at the actual response to see the issue. It could be an error response, or some variant you did not code for.

    0 comments No comments