doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Connect exception #243

Closed AUrban closed 2 years ago

AUrban commented 2 years ago

Hi @doghappy!

I've got this exception when trying to connect to socket.io server:

** Exception Text ** 12:57:26 [FTL] : System.InvalidOperationException: The requested operation requires an element of type 'Number', but the target element has type 'String'. at System.Text.Json.JsonDocument.TryGetValue(Int32 index, Int32& value) at System.Text.Json.JsonElement.GetInt32() at SocketIOClient.Messages.OpenedMessage.Read(String msg) at SocketIOClient.Messages.MessageFactory.CreateMessage(Int32 eio, String msg) at SocketIOClient.Transport.TransportRouter.OnTextReceived(String text) at System.Threading.Tasks.Task.<>c.b__140_1(Object state) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch()

I'v reseached the problem and found that the cause is in these rows (in the Read method of the OpenedMessage class):


PingInterval = root.GetProperty("pingInterval").GetInt32(); PingTimeout = root.GetProperty("pingTimeout").GetInt32();


With this, the message looks like this: {"sid":"zW8GQnX9N0bPS1tUAARQ","upgrades":[],"pingInterval":"15000","pingTimeout":"10000"}

if corrected as follows, the problem disappears:


PingInterval = Int32.Parse(root.GetProperty("pingInterval").GetString()); PingTimeout = Int32.Parse(root.GetProperty("pingTimeout").GetString());


What could be wrong? Could you please give me a recommendation how to avoid such problems?

doghappy commented 2 years ago

Maybe the message you received is a special case, I received this:

{"sid":"BpXgajlbwVH1qR4QBvKz","upgrades":[],"pingInterval":10000,"pingTimeout":5000}

Which version of socket.io server do you use?

AUrban commented 2 years ago

Hello! The service is compatible with the following librariy for Socket.IO: 2.3.0

AUrban commented 2 years ago

Hi!

Do you have any idea about what might be wrong?

doghappy commented 2 years ago

https://github.com/doghappy/socket.io-client-csharp/commit/212cade46ae0785ff0600791f0a694e997e5bd86

AUrban commented 2 years ago

Hi! Looks good. When are going to release that?

AUrban commented 2 years ago

The thing is I'm using this library via NuGet

doghappy commented 2 years ago

has been released