JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.03k stars 425 forks source link

Uncatched exception on the newest version #955

Open NektoDron opened 2 years ago

NektoDron commented 2 years ago

13:07:13.31[2]FATAL:UnobservedTaskException: AggregateException: InvalidOperationException:The WebSocket is not connected.:Exception:

The WebSocket is not connected.

System.InvalidOperationException

Stack Trace: at System.Net.WebSockets.ClientWebSocket.get_ConnectedWebSocket() at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.ReceiveLoopAsync()

13:09:03.17[2]FATAL:UnobservedTaskException: AggregateException: ObjectDisposedException:Cannot access a disposed object. Object name: 'SecureString'.:Exception:

Cannot access a disposed object. Object name: 'SecureString'.

System.ObjectDisposedException

Stack Trace: at System.Security.SecureString.EnsureNotDisposed() at CryptoExchange.Net.ExtensionMethods.GetString(SecureString source) at Binance.Net.BinanceAuthenticationProvider.AddAuthenticationToHeaders(String uri, HttpMethod method, Dictionary2 parameters, Boolean signed, HttpMethodParameterPosition parameterPosition, ArrayParametersSerialization arraySerialization) at CryptoExchange.Net.RestClient.ConstructRequest(Uri uri, HttpMethod method, Dictionary2 parameters, Boolean signed, HttpMethodParameterPosition parameterPosition, ArrayParametersSerialization arraySerialization, Int32 requestId, Dictionary2 additionalHeaders) at CryptoExchange.Net.RestClient.SendRequestAsync[T](Uri uri, HttpMethod method, CancellationToken cancellationToken, Dictionary2 parameters, Boolean signed, Boolean checkResult, Nullable1 parameterPosition, Nullable1 arraySerialization, Int32 credits, JsonSerializer deserializer, Dictionary`2 additionalHeaders) at Binance.Net.SubClients.Spot.BinanceClientSpotSystem.GetServerTimeAsync(Boolean resetAutoTimestamp, CancellationToken ct)

13:09:19.26[2]FATAL:UnobservedTaskException: AggregateException: ObjectDisposedException:The CancellationTokenSource has been disposed.:Exception:

The CancellationTokenSource has been disposed.

System.ObjectDisposedException

Stack Trace: at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.SendLoopAsync()

kamranhuseyns commented 2 years ago

Hi . You have to set your ApiKey

NektoDron commented 2 years ago

Hi, it was set. It happens if connection was lost

JKorf commented 2 years ago

Hi, is this with alpha1 or alpha2?

NektoDron commented 2 years ago

release 7.2.6 execution - net 6.0

JKorf commented 2 years ago

Do you have any additional logging? Do you have any connectionlost/restored handling?

NektoDron commented 2 years ago

Additional logging was disabled. Connectionlost/restored handling has only SubscribeToUserDataUpdatesAsync stream. if connection lost will be initiated full reconnection (new BinanceSocketClient will be created).

JKorf commented 2 years ago

Can you show me how that code works?

NektoDron commented 2 years ago

It disposes the BinanceClient and BinanceSocketClient and makes new instances.

JKorf commented 2 years ago

You're disposing the socket client in the ConnectionLost event? I can imagine that doesn't work. Any reason you're not using the default reconnect handling?

NektoDron commented 2 years ago

Because it was written before reconnection handling appeared, and worked fine some years.

NektoDron commented 2 years ago

And it disposed not on ConnectionLost. It disposed if some abnormal error was happened. For example, invalid listen key in KeepAliveUserStreamAsync call.