Nethereum: Nethereum.JsonRpc.RpcClient - Error occurred when trying to send rpc requests(s)
Hi,
I have tried to use your library and I have a problem.
My code is very simple:
var web3 = new Web3("https://mainnet.infura.io");
var balance = web3.Eth.GetBalance.SendRequestAsync("0xB5c15851bb50b0f43F743c30dFaDf3F6F512d494").Result;
var value = Web3.Convert.FromWeiToBigDecimal(balance);
var str = value.ToString();
and I get a exception on SendRequestAsync. Here is my exception:
System.AggregateException was unhandled by user code
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at WFA_Nethereum01.Form1.<bRefreshBalance_Click>d__1.MoveNext() in D:\Lada\Nethereum\WFA_Nethereum01\WFA_Nethereum01\Form1.cs:line 51
InnerException:
HResult=-2146233088
Message=Error occurred when trying to send rpc requests(s)
Source=Nethereum.JsonRpc.RpcClient
StackTrace:
at Nethereum.JsonRpc.Client.RpcClient.<SendAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.JsonRpc.Client.RpcClient.<SendInnerRequestAync>d__12`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.JsonRpc.Client.ClientBase.<SendRequestAsync>d__8`1.MoveNext()
InnerException:
HResult=-2146233088
Message=There was an error sending request.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Nethereum.JsonRpc.Client.RpcClient.<SendAsync>d__17.MoveNext()
InnerException:
HResult=-2146233079
Message=Parent connection closed: An unexpected error occurred while sending.
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
InnerException:
HResult=-2146232800
Message=Unable to read data from the transport connection: Existing connection has been forced terminated by a remote host.
Source=System
StackTrace:
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
InnerException:
ErrorCode=10054
HResult=-2147467259
Message=Existing connections have been forced terminated by a remote host
NativeErrorCode=10054
Source=System
StackTrace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
InnerException:
I don’t know where is the problem. Can you help me?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 30 (12 by maintainers)
This is working for me Thanks
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
@juzer-hakimji I had the same issue. Probably the infura project id in the nethereum docs is expired. I just got a new project id from infura.io and changed it as https://mainnet.infura.io/v3/my_project_id in the code(new Web3) and it resolved. I hope this works for you too.
Hi, I use version 4.6.1 and you have true. The problem was in TLS. Solution:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;Ahh ok got it. Thanks for your help 😃
Ah, you need to set the web3.Eth.TransactionManager to Legacy Mode.
@alejandrasg @Khay-EMMA can you post a sample ? Are you using the settings at the bottom of the docs: https://docs.nethereum.com/en/latest/Nethereum.Workbooks/docs/nethereum-gettingstarted-infura
Note: some communication errors can occur with INFURA if INFURA’s API and your app can’t agree on what version of TLS to use. .Net 4.5 and earlier will default to TLS v1, with TLS v1.2 deactivated if it’s included in the framework. (In .Net 4.6.*, v1.2 is the default.)
To enable v1.2 in 4.5.2 you can use:
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;Notice the use of |= to turn on 1.2 without affecting other protocols (that way you remain able to take advantage of future TLS versions that may become the default values in future updates to .NET).
Or may work better for you, as per the comments:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;