I work with project asp core 5.0, I call external API to my API Controller using HTTP Client and The error
A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
Controller.cs
public async Task<AuthDataAttributesResponseDTO> AuthenticationTest(AuthDTO input)
{
var model = new AuthDataAttributesDTO
{
type = "authentication",
attributes = input
};
using (var httpClient = new HttpClient())
{
StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
using (var response = await httpClient.PostAsync("https://X.XX.XX.XX/api/v1/oauth2/access-token", content))
{
string apiResponse = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<AuthDataAttributesResponseDTO>(apiResponse);
}
}
}