CsvReader read stream from Request Body in Asp.net core MVC occured unhandled exception.
■Exception
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
[ActionName("SaveLog")]
[HttpPost]
public IActionResult SaveLog([FromHeader] HeaderDTO headerDTO)
{
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
//ヘッダを出力しないように指定
HasHeaderRecord = false,
};
using (var reader = new StreamReader(Request.Body))
using (var csv = new CsvReader(reader, config))
{
var records = csv.GetRecords<Operationlog>().ToList();
}
return Ok();
}
You are being affected by a breaking change from ASP.NET Core 3.0.
HTTP: Synchronous IO disabled in all servers
The package CsvHelper already addressed it ,Convert your controller method to async and just call the async equivalent of the method in CsvHelper: