pact-workshop-dotnet-core-v1 icon indicating copy to clipboard operation
pact-workshop-dotnet-core-v1 copied to clipboard

ProviderStateMiddleware Synchronous IO operation throws error

Open Issafalcon opened this issue 5 years ago • 0 comments
trafficstars

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<KestrelServerOptions>(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.

Issafalcon avatar Oct 21 '20 09:10 Issafalcon