My old .net core 2 web api project used newtonsoft to serialise a datatable to json which I then passed back to a front end (angular) site as json ie using something along the lines of:
- Create a function ie
public IActionResult Countries_Get()
, query a sql server database and populate a new sql datatable ieDataTable dtCountries = clsDB.Execute_To_DataTable("selCountries", lstDBParams, Request);
. - Return the datatable from the function with a HTTPStatusCode such as Ok ie
return Ok(dtCountries);
The code above no longer works in a .net 5.0 project (started fresh) with an error of System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues. Path: $.Columns.DataType.
I've read that this is by design from Microsoft as it's insecure using the new System.Text.Json namespace, I really want to do it the right way going forward, but after hours of searching am no closer to the answer.
Can someone please advise how to do the above which does the same thing as the original application.
Cheers