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
.