JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than

后端 未结 6 988
执念已碎
执念已碎 2021-02-04 16:07

In my web api when i run project for get data from database got this error .net core 3.1

JsonException: A possible object cycle was detected which is not

6条回答
  •  青春惊慌失措
    2021-02-04 16:22

    I have the same issue, my fix was to add async and await keyword since I am calling an async method on my business logic.

    Here is my original code:

    [HttpGet]
    public IActionResult Get()
    {
       //This is async method and I am not using await and async feature .NET which triggers the error
       var results = _repository.GetAllDataAsync(); 
       return Ok(results);
    }
    

    To this one:

    HttpGet]
    public async Task Get()
    {
       var results = await _repository.GetAllDataAsync();
       return Ok(results);
    }
    

提交回复
热议问题