3

The stack trace details:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at MySql.Data.MySqlClient.NativeDriver.StartSSL()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at WebAppClassLibrary.MySqlShell.ExecuteScalar(String query, MySqlConnection mySqlConnection, MySqlParameter[] mySqlParameters) in N:\webApp\WebAppClassLibrary\MySqlShell.cs:line 147
at WebAppClassLibrary.ServiceOperations.GetServiceType(Int32 login) in N:\webApp\WebAppClassLibrary\ServiceOperations.cs:line 57
at WebAppClassLibrary.PartnerDetailLibrary.GetAccountData(PartnerDetailAccount partnerDetailAccount, MySqlConnection mtInstaConnection, MySqlConnection secureConnection, MySqlParameter paramStartTime, MySqlParameter paramEndTime, Dictionary`2 lastActivity, Dictionary`2 balances, Boolean exactPeriod, Boolean allowProfit, Boolean allowEquity, Boolean allowAdditionalPercentFor, Boolean usingCache, Boolean IsCryptoOnly, Double minCommission, Boolean showAgent) in N:\webApp\WebAppClassLibrary\PartnerDetailLibrary.cs:line 40
at PartnerDetail.<>c_DisplayClass118_0.<FillDataGridByClients>b_1(Int32 i) in N:\webApp\WebApp\PartnerDetail.aspx.cs:line 0
at System.Threading.Tasks.Parallel.<>c_DisplayClass17_0`1.<ForWorker>b_1()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c_DisplayClass176_0.<ExecuteSelfReplicating>b_0(Object )
— End of inner exception stack trace —
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)
at PartnerDetail.FillDataGridByClients(Int32 from, Int32 to) in N:\webApp\WebApp\PartnerDetail.aspx.cs:line 1129
at PartnerDetail.BtnSearchClick(Object sender, EventArgs e) in N:\webApp\WebApp\PartnerDetail.aspx.cs:line 566
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
---> (Inner Exception #0) System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at MySql.Data.MySqlClient.NativeDriver.StartSSL()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at WebAppClassLibrary.MySqlShell.ExecuteScalar(String query, MySqlConnection mySqlConnection, MySqlParameter[] mySqlParameters) in N:\webApp\WebAppClassLibrary\MySqlShell.cs:line 147
at WebAppClassLibrary.ServiceOperations.GetServiceType(Int32 login) in N:\webApp\WebAppClassLibrary\ServiceOperations.cs:line 57
at WebAppClassLibrary.PartnerDetailLibrary.GetAccountData(PartnerDetailAccount partnerDetailAccount, MySqlConnection mtInstaConnection, MySqlConnection secureConnection, MySqlParameter paramStartTime, MySqlParameter paramEndTime, Dictionary`2 lastActivity, Dictionary`2 balances, Boolean exactPeriod, Boolean allowProfit, Boolean allowEquity, Boolean allowAdditionalPercentFor, Boolean usingCache, Boolean IsCryptoOnly, Double minCommission, Boolean showAgent) in N:\webApp\WebAppClassLibrary\PartnerDetailLibrary.cs:line 40
at PartnerDetail.<>c_DisplayClass118_0.<FillDataGridByClients>b_1(Int32 i) in N:\webApp\WebApp\PartnerDetail.aspx.cs:line 0
at System.Threading.Tasks.Parallel.<>c_DisplayClass17_0`1.<ForWorker>b_1()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c_DisplayClass176_0.<ExecuteSelfReplicating>b_0(Object )<---

at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.agentsdetalization_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\79e9f1d9\6267efd7\App_Web_fixgkyq0.4.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I am getting this rear exception but surely approximately 1 or 2 times in every 1000 requests. Though I tried to rid this in different ways, but could not get any solution instead of dilemmas.

I went through this question similar to my exception, but there is no solution yet. I also found this question, but just fall in dilemma now what would be the solution for my exception. And I tried to write this piece of line in method Global.asax.cs/Application_BeginRequest():

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

Note: my application's target .NET framework version is 4.7, and I have to fix this exception in my application code. I don't have right to work on the server. So, please help me if I am in the correct way or not. Also, please ensure if this line of code is relevant to my exception. If this is correct, should I use bitwise shorthand operator '|=' in place '=' at the above line of code?

Thanks in advance.

UPDATE: Full stack trace and exception details added at the bottom of the code block as some persons asked to help to understand. Please note that, james-mead's answer doesn't work yet. I would like to ask more answers from experts to get rid of this exception. I am really stuck at this point.

X-Coder
  • 2,632
  • 2
  • 19
  • 17
  • 2
    What's in line 94 from MyLibrary.cs? Best to share the cs file here too. The error is simply saying the code cannot do anything with a zero byte stream. It sounds like every 1000 records, you're not feeding in anything into the code. It could be a simple matter of skipping blank/empty stream data? – Fandango68 Jul 15 '20 at 02:22
  • Did you try validating the certificate before making the call? https://forums.asp.net/t/2054166.aspx?Received+an+unexpected+EOF+or+0+bytes+from+the+transport+stream – Durga Prasad Jul 15 '20 at 04:14
  • @Fandango68 rest of lines aren't needed at all. However, are you suggesting to call the method MySqlShell.ExecuteScalar() inside try-catch block in method GetAccountData()? I can handle the exeption simply inside try-catch, but I would like to know if there is any solution not to happen this exception again later. Is there any configuration needed on the application side? Thanks! – X-Coder Jul 15 '20 at 06:49
  • @DurgaPrasad: it wasn't tried. Coz, this exception is happening rarely. So, for each call to db, I don't want to validate the server certificate. You may write your thoughts again. Thanks! – X-Coder Jul 15 '20 at 07:19
  • 2
    Without seeing more code, I can't really help you. – Fandango68 Jul 16 '20 at 04:21
  • Authentication happens all the time when you make a connection. What I am asking you to do is put a callback in place so that if the server is not authenticated properly we will skip the request entirely. – Durga Prasad Jul 17 '20 at 12:49
  • 2
    You can try a try/catch like you suggested. When this happens, examine the details of the exception, and what the sql statement from your ExecuteScalar call is. You may find some specific issue or combination of parameters which only surface 0. 2% of the time. Also consider tracing your sql statements to see the issue with whatever you're passing to ExecuteScalar. – deanis Jul 18 '20 at 22:11
  • @Fandango68 Hi, could you please help now? I have shared full detail as you asked. I am really stuck at this point. Thanks! – X-Coder Oct 28 '20 at 06:18

1 Answers1

1

Change:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

To:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)12288
                                     | (SecurityProtocolType)3072
                                     | (SecurityProtocolType)768;
                                     | SecurityProtocolType.Tls;

Obviously you need to run this code before making the first HTTP request. To make sure the most recent TLS version is used you need to try catch it. Something like this:

try {
    ServicePointManager.SecurityProtocol = (SecurityProtocolType) 12288
            | (SecurityProtocolType) 3072
            | (SecurityProtocolType) 768
            | SecurityProtocolType.Tls;
} catch (NotSupportedException) {
    try {
        ServicePointManager.SecurityProtocol = (SecurityProtocolType) 3072
                | (SecurityProtocolType) 768
                | SecurityProtocolType.Tls;
    } catch (NotSupportedException) {
        try {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType) 768
                    | SecurityProtocolType.Tls;
        } catch (NotSupportedException) {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
        }
    }
}
Dan M
  • 4,340
  • 8
  • 20
  • why should typecast whereas we have SecurityProtocolType enum values directly? – X-Coder Jul 22 '20 at 11:01
  • Obvious question, but I had cases where that's the only way it would work. But I am curious, did this solve your problem? – Dan M Jul 22 '20 at 19:10
  • Hello, it doesn't work yet, still the problem exists. I have shared full detail, could you please take look again. Thanks! – X-Coder Oct 28 '20 at 06:20