skip to Main Content
        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


  1. 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; }
    }
    

    Here is Newtonsoft Reference

    Login or Signup to reply.
  2. 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>

    Login or Signup to reply.
  3. Adding await in controller before service method invokation solved the problem for me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search