Quantcast
Channel: User Simon_Weaver - Stack Overflow
Viewing all articles
Browse latest Browse all 116

Answer by Simon_Weaver for JSON.Net Self referencing loop detected

$
0
0

Make sure you aren't accidentally serializing a Task<T>

You can get this error if you forget to await an asynchronous method whose return value you intended to serialize.

    public async Task<JsonResult> GetTaxTable([FromServices] TaxService taxService)    {        var taxTable = /* await */ taxService.GetTaxTable();        return new JsonResult(taxTable);    }

In this example I had forgotten to await the GetTaxTable async method. So I inadvertently ended up passing a Task to the JsonResult constructor - and a Task isn't serializable. While it may at first look like everything blew up on you - the simple solution is to add await.


Viewing all articles
Browse latest Browse all 116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>