I've just successfully retargeted my Web API app from .NET Framework 4.7.1 to .NET Core 2.1. The application runs perfectly on my local machine.

After deploying it to an Azure app service the app starts up and looks healthy. However I log the following error whenever I make any API call (including to receive static files).

Microsoft.AspNetCore.Server.Kestrel: Connection id "0HLIFNSQMBR9Q", Request id "0HLIFNSQMBR9Q:0000000D": An unhandled exception was thrown by the application. System.ObjectDisposedException: Cannot access a disposed object. Object name: 'FrameResponseStream'. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.ValidateState(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.Write(String value) at Microsoft.AspNetCore.Hosting.Views.ErrorPage.ExecuteAsync() at Microsoft.Extensions.RazorViews.BaseView.ExecuteAsync(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.ProcessRequestsAsync()

Unfortunately the above stack trace does not mention any of our code, and so I'm not entirely sure where this exception is coming from. This error did not occur when .NET Framework was targeted, so it must be related to the retargeting to .NET Core 2.1.

I have checked this StackOverflow question which also describes the exception after migrating to .NET Core 2.1, but I've tried looking for and fixing the situations described in the answers without success.

What could be causing this error and how can I fix it?

0

There are 0 best solutions below