私は一貫性がなく、頻繁に発生した次の例外があります。JSONシリアル化エラーをデバッグする方法は?
System.Exception: Serialization error - One or more errors occurred., Unexpected character encountered while parsing value: <. Path '', line 0, position 0., System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
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 Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.b__1(String raw)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass19`2.b__17(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass42.b__41(Task`1 t)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
**at Project.Services.NotificationService.SignalObjectToUser(Object data, String username, Boolean isTypingNotification)
---> (Inner Exception #0) Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.**
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
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 Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.b__1(String raw)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass19`2.b__17(Task`1 t)
重要なビット:そこ
**at Project.Services.NotificationService.SignalObjectToUser(Object data, String username, Boolean isTypingNotification)
---> (Inner Exception #0) Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.**
マイコード:
private void SignalObjectToUser(object data, string username, bool isTypingNotification = false) {
try {
_hubConnection = new HubConnection(_baseUrl);
_hubConnection.CookieContainer = new CookieContainer();
_hubConnection.CookieContainer.Add(_cookie);
_hubProxy = _hubConnection.CreateHubProxy("appHub");
_hubConnection.Start().Wait();
string serialized = null;
try {
List<string> errors = new List<string>();
serialized = JsonConvert.SerializeObject(data, new JsonSerializerSettings() {
Error = delegate(object sender, ErrorEventArgs args) {
errors.Add(args.ErrorContext.Error.Message);
args.ErrorContext.Handled = true;
Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Delegated serialization error - " + args.ErrorContext.Error.Message));
}
});
_hubProxy.Invoke((isTypingNotification ? "SendTypingNotification" : "SendClientNotification"), serialized, username).Wait();
}
catch (Exception exception) {
Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Serialization error - " + exception.Message + ", " + exception.InnerException.Message + ", " + exception.ToString()));
throw new Exception("Messaging Error");
}
}
catch (Exception e) {
Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Serialization error - " + e.Message + ", " + e.InnerException.Message + ", " + e.ToString()));
throw new Exception("Messaging Error");
}
}
を私は何を把握しようとしているしかし、正確にがこの問題を引き起こしています。私はどのようなキー/値のペアが例外を生成しているのかわかりません。ここではどのようにもっと詳細な情報を集めることができますか?
エラーは、予期しない文字は、0行目、0行目で '<'であると言います。XMLをJSONデシリアライザに渡していますか?もしそうなら、それが問題です。有効なJSONは '<'で始まることはありません。 –
@BrianRogers私は何とかしているようですが、どのように、いつ、いつかは分かりません。私はシリアル化の問題を見ることができるように、あらかじめシリアル化する方法があることを願っています。 – RobVious