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