I am moving my class library helper for HttpWebRequest
(standard .net class) from .NET 4.6.2 to .NET core 3.1 .
And I discovered the following issue with .NET core 3.1 : When I call responseStream.BeginRead
it calls via the Stack: So it is the reason of issue. when stack ends application fails due to stack overflow error.
.NET 4.6.2 behavior is different - it calls BeginRead
on Thread Pool. And it works right for years without any issue.
I cannot find the reason why .NET core 3.1 has different behavior for BeginRead
.
If you know how to fix HttpWebRequest
BeginRead
or any ideas share with me, please.
It is standart behaviour for .net core and your code has to be ready for that.
You have to analyse in your code ReadIAsyncResult.CompletedSynchronously == true/false and decide what to do this that if CompletedSynchronously == true your have to return from the function.
Check docs
https://learn.microsoft.com/en-us/do.net/api/system.iasyncresult.completedsynchronously?view.net-7.0
Notes to Implementers Most implementers of the IAsyncResult interface will not use this property and should return false. Beginning with the .NET Framework 4.5, a task that is created with the FromAsync(IAsyncResult, Action, TaskCreationOptions) method will not complete if this property is not implemented correctly. See Application Compatibility in 4.5.
Notes to Callers Use this property to determine if the asynchronous operation completed synchronously. For example, this property can return true for an asynchronous I/O operation if the I/O request was small.
Find more details here https://github.com/microsoft/referencesource/issues/177
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.