0

有时,我在初始化时收到 Newtonsoft.Json.JsonReaderException。我正在使用来自 Git 的 PusherClient 库。异常是在不同的线程上抛出的,特别麻烦。我在初始化中没有做任何特别的事情。我想我直接从 Pusher .NET 示例中得到了这段代码:

if (!_isInitialized)
{
    _pusher = new Pusher(_pusherKey);
    _pusher.Connected += PusherConnected;
    _pusher.ChannelAuthEndpoint = _authUri + HttpUtility.UrlEncode(_clientName);
    _pusher.ConnectionStateChanged += PusherOnConnectionStateChanged;
    _pusher.Connect();
}

Pusher Auth Endpoint 是我在此初始化链中唯一拥有的其他组件,它使用 PusherProvider(在 PusherRESTDotNet 库中提供)来验证私有和在线通道请求。身份验证提供程序中没有抛出异常。

我可以向这些库添加额外的日志记录,以发现正在发送的内容,以及导致 JSON 库打嗝的原因,但我不确定从 Pusher 的角度来看恢复路径应该是什么;我试图保持 Pusher .NET 库的黑盒消费者。任何想法/想法表示赞赏。

当它成功时,我从 Pusher 跟踪日志中得到以下信息:

Pusher Information: 0 : Websocket opened OK.
Pusher Information: 0 : Websocket message received: {"event":"pusher:connection_established","data":"{\"socket_id\":\"24213.760310\"}"}
Pusher Information: 0 : Websocket message received: {"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"private-HW-PusherChannel"}
Pusher Information: 0 : Websocket message received: {"event":"pusher_internal:subscription_succeeded","data":"{\"presence\":{\"count\":2,\"ids\":[\"24213.760310\",\"24305.693765\"],\"hash\":{\"24213.760310\":{\"name\":\"SITE2\"},\"24305.693765\":{\"name\":\"SITE1\"}}}}","channel":"presence-channel"}

失败时会出现以下情况:

Pusher Information: 0 : Websocket opened OK.
Pusher Information: 0 : Websocket message received: {"event":"pusher:connection_established","data":"{\"socket_id\":\"24102.767432\"}"}
Pusher Information: 0 : Websocket message received: {"event":"pusher_internal:subscription_succeeded","data":"{\"presence\":{\"count\":2,\"ids\":[\"24102.767432\",\"24305.693765\"],\"hash\":{\"24102.767432\":{\"name\":\"SITE2\"},\"24305.693765\":{\"name\":\"SITE1\"}}}}","channel":"presence-channel"}
Pusher Information: 0 : Websocket message received: {"event":"pusher:error","data":{"code":null,"message":"Cannot broadcast client event (connection not subscribed to channel private-HW-PusherChannel)"}}

完整的堆栈如下:

Exception: Newtonsoft.Json.JsonReaderException: Error reading string. Unexpected token: StartObject. Path 'data', line 1, position 32.
   at Newtonsoft.Json.JsonReader.ReadAsStringInternal()
   at Newtonsoft.Json.JsonTextReader.ReadAsString()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndConstructorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectFromNonDefaultConstructor(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ConstructorInfo constructorInfo, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultConstructor)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at Newtonsoft.Json.JsonConvert.DeserializeAnonymousType[T](String value, T anonymousTypeObject)
   at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e) in C:\svn\non-scm\pusher-dotnet-client\PusherClient\Connection.cs:line 98
   at WebSocket4Net.WebSocket.FireMessageReceived(String message)
   at WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
   at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
   at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted(Object sender, SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object ignored)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
   at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
4

0 回答 0