doghappy / socket.io-client-csharp

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

Getting System.Text.Json.JsonReaderException #224

Open jasonItotal opened 2 years ago

jasonItotal commented 2 years ago

Full Exception:

System.Text.Json.JsonReaderException: 'The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.'

This exception was originally thrown at this call stack: [External Code]

Target Framework: .Net Framework 4.7.2 Client side code sample:

var client = new SocketIO(target, new SocketIOOptions
{
    Query = new List<KeyValuePair<string, string>>
    {
        new KeyValuePair<string, string>("token", "token")
    }
});
client.On("connected", async response =>
{
    await client.EmitAsync("test_event");
});
await client.ConnectAsync();

Server side code sample:

io.on('connection', (socket) => {
    socket.emit('connected',{
        user_id: 1,
        user_name: 'test user',
    })
})
doghappy commented 2 years ago

This error cannot be reproduced, it may be caused by other reasons. Can you show detailed stack information?

lothar100 commented 2 years ago

I also have this error. Targeting ASP .Net Core 3.1 Any help solving the issue would be appreciated. I'm basically stuck.

System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonDocument.Parse(ReadOnlySpan1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack) at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedBytes) at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 json, JsonDocumentOptions options) at System.Text.Json.JsonDocument.Parse(String json, JsonDocumentOptions options) at SocketIOClient.Messages.ConnectedMessage.Eio4Read(String msg) at SocketIOClient.Messages.ConnectedMessage.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__139_1(Object state) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

lothar100 commented 2 years ago

It looks like setting EIO = 3 in the SocketIOOptions fixed the issue.