Search code examples
restsharp

RestSharp ExecAsync<T> where T is a nested object


I have a method that calls RestSharp client ExecuteAsync<T> where the T I am passing is a nested object. I get an exception that says

InvalidProgramException: Request for the resource /v1/accounts/AN_1476935163870 failed No parameterless constructor defined for this object.

The object I am passing is:

public class GetAccountResponse : IGetAccountResponse
    {
        public GetAccountResponseBasicInfo basicInfo { get; set; }
        public GetAccountResponseBillingAndPayment billingAndPayment { get; set; }
        public GetAccountResponseMetrics metrics { get; set; }
        public string billToContact { get; set; }
        public string soldToContact { get; set; }
        public bool success { get; set; }
    }

Where the objects for the properties basicInfo, billingAndPayment, and metrics are classes that have definitions and I have not defined a consturctor. I also have tried replacing the objects with interfaces but it still throws an exception.

Thank you


Solution

  • There are two possible causes of this issue:

    • Regression in RestSharp that added the new constraint to typed request methods, which was fixed this week
    • Serialization issue. In that case, you can try another serializer, we have libraries that support NewtosoftJson, Utf8Json and System.Text.Json in addition to the built-in SimpleJson