Reputation: 63
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.
Upvotes: 5
Views: 6864
Reputation: 546
Adding await
in controller before service method invokation solved the problem for me
Upvotes: 5
Reputation: 6035
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 a Task<IActionResult>
Upvotes: 1
Reputation: 777
So without knowing the structure of the data
I can only assume the following. You have a Class that has a definition of Action
in it. Something like the following.
public class YourData
{
public string Name { get; set; }
public Action TheAction { get; set; }
}
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
[JsonObject(MemberSerialization.OptIn)]
public class ClassWithAction
{
[JsonProperty]
public string Name { get; set; }
public Action TheAction { get; set; }
}
Upvotes: 0