var json = JsonConvert.SerializeObject(data);
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
var httpContent = new MultipartFormDataContent();
httpContent.Add(stringContent, "params");
using var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
var httpClient = new HttpClient(httpClientHandler);
var response = await httpClient.PostAsync(url, httpContent);
response.EnsureSuccessStatusCode();
if (!response.IsSuccessStatusCode)
I was trying to send http request, but got an exception on PostAsync() line
System.NotSupportedException: Serialization and deserialization of
‘System.Action’ instances are not supported. Path: $.MoveNextAction.
3
Answers
So without knowing the structure of the
data
I can only assume the following. You have a Class that has a definition ofAction
in it. Something like the following.When you try to serialize it you receive the exception. If that is what you are experiencing you will need to update your class that represents your data and add attributes to it, this will exclude the properties that you do not want/can’t serialize. Something like the following
Here is Newtonsoft Reference
Switch the return type for the controllers to
Task<IActionResult>
.I faced this issue when I was switching to using the Task Parallel Library’s async-await implementation but let my controllers return an
IActionResult
instead of aTask<IActionResult>
Adding
await
in controller before service method invokation solved the problem for me