在Pusher Initialization上抛出Newtonsoft.Json.JsonReaderException

时间:2013-03-17 21:05:06

标签: c# .net pusher

有时,我在初始化时遇到了Newtonsoft.Json.JsonReaderException。我正在使用Git的PusherClient库。异常抛出在另一个线程上,这特别麻烦。我在init中没有做任何特别的事情。我想我直接从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库中提供)来验证私有和在线通道请求。在auth提供程序中没有抛出异常。

我可以向这些库添加额外的日志记录,以发现正在发送的内容,以及导致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)

0 个答案:

没有答案
相关问题