When targetting netcoreapp3.1 in the workshop project, using the prescribed Startup file from the workshop along with the ProviderStateMiddleware leads to an error at the following call:
jsonRequestBody = reader.ReadToEnd();
The error message is:
Microsoft.AspNetCore.Server.Kestrel: Error: Connection id "0HM3LKBBJTAHT", Request id "0HM3LKBBJTAHT:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at Waters.AuditLogAS.ContractTests.Middleware.ProviderStateMiddleware.HandleProviderStatesRequest(HttpContext context) in /home/ukafig/Repositories/auditlogas/ContractTests/Middleware/ProviderStateMiddleware.cs:line 47
at Waters.AuditLogAS.ContractTests.Middleware.ProviderStateMiddleware.Invoke(HttpContext context) in /home/ukafig/Repositories/auditlogas/ContractTests/Middleware/ProviderStateMiddleware.cs:line 28
When targetting netcoreapp3.1 in the workshop project, using the prescribed Startup file from the workshop along with the ProviderStateMiddleware leads to an error at the following call:
jsonRequestBody = reader.ReadToEnd();
The error message is:
Microsoft.AspNetCore.Server.Kestrel: Error: Connection id "0HM3LKBBJTAHT", Request id "0HM3LKBBJTAHT:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamReader.ReadBuffer() at System.IO.StreamReader.ReadToEnd() at Waters.AuditLogAS.ContractTests.Middleware.ProviderStateMiddleware.HandleProviderStatesRequest(HttpContext context) in /home/ukafig/Repositories/auditlogas/ContractTests/Middleware/ProviderStateMiddleware.cs:line 47 at Waters.AuditLogAS.ContractTests.Middleware.ProviderStateMiddleware.Invoke(HttpContext context) in /home/ukafig/Repositories/auditlogas/ContractTests/Middleware/ProviderStateMiddleware.cs:line 28
The issue pertains to the following https://github.com/dotnet/aspnetcore/issues/7644.
The solution is to add the following to ConfigureServices:
services.Configure(options =>
{
options.AllowSynchronousIO = true;
});
I am happy to submit a PR with the above to ensure workshop code is compatible with .net core 3.1.