JsonSerializationException on Home Timeline & others

Aug 4, 2015 at 11:35 AM
Edited Aug 4, 2015 at 11:35 AM
Hi Linvi,
I Have received 37 counts of JsonSerializationException since putting the production code onto Tweetinvi 0.9.9.1 (upgraded from 0.9.8.2) about half an hour ago.
They have mostly been on the Home Timeline, but there has also been some on the User Timeline and Latest Messages Sent (Outbound Direct Messages).

Home Timeline:
2015-08-04 11:03:09 - TwitterRestPoller.Program: Error: Exception whilst fetching User Home Feed. Exception:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Tweetinvi.Core.Interfaces.DTO.ITweetDTO]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'request', line 1, position 11.
   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, JsonConverter[] converters)
   at Tweetinvi.Logic.JsonConverters.JsonObjectConverter.DeserializeObject[T](String json, JsonConverter[] converters)
   at Tweetinvi.Controllers.Timeline.TimelineController.GetHomeTimeline(IHomeTimelineParameters parameters)
   at TwitterRestPoller.Program.fetchUserHomeFeed(TwitterAccount user, Nullable`1 sinceId) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 621
   at TwitterRestPoller.Program.pollUserHomeFeed(TwitterAccount user) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 585
User Timeline:
2015-08-04 10:52:14 - TwitterRestPoller.Program+<>c__DisplayClass1a: Error: Exception whilst fetching User Timeline. Exception:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Tweetinvi.Core.Interfaces.DTO.ITweetDTO]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'request', line 1, position 11.
   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, JsonConverter[] converters)
   at Tweetinvi.Logic.JsonConverters.JsonObjectConverter.DeserializeObject[T](String json, JsonConverter[] converters)
   at Tweetinvi.Controllers.Timeline.TimelineController.GetUserTimeline(IUserTimelineQueryParameters queryParameters)
   at TwitterRestPoller.Program.fetchUserTimeline(TwitterAccount user) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 683
   at TwitterRestPoller.Program.<>c__DisplayClass1a.<fetchUserTimelineAsync>b__19() in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 670
Latest Messages Sent (Outbound Direct Messages):
2015-08-04 10:59:59 - TwitterRestPoller.Program: Error: Exception whilst fetching User Direct Messages (Outbound). Exception:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Tweetinvi.Core.Interfaces.DTO.IMessageDTO]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'errors', line 1, position 10.
   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, JsonConverter[] converters)
   at Tweetinvi.Logic.JsonConverters.JsonObjectConverter.DeserializeObject[T](String json, JsonConverter[] converters)
   at Tweetinvi.Controllers.Messages.MessageController.GetLatestMessagesSent(IMessageGetLatestsSentRequestParameters messageGetLatestsSentRequestParameters)
   at TwitterRestPoller.Program.fetchUserDirectMessagesOutbound(TwitterAccount user, Nullable`1 sinceId) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 429
   at TwitterRestPoller.Program.pollUserDirectMessagesOutbound(TwitterAccount user) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 391
Can you advise if you will have time to look into this today, as otherwise I'll need to roll back to 0.9.8.2?
Cheers,
Josh
Coordinator
Aug 4, 2015 at 11:39 AM
Oh ghosh this is a pretty bad bug.

I will look into this today, but please rollback for the moment, I will get version 0.9.9.1 out of nuget for now.

Sorry about this.
Thanks for the feedback.
Coordinator
Aug 4, 2015 at 11:42 AM
Could you let me know for which user timeline this is happening (privately if needed).
Aug 4, 2015 at 11:54 AM
I don't know which user each exception corresponds with, as I haven't logged that.

I have just reproduced it on my machine though, for Inbound Direct Messages (GetLatestMessagesReceived) with Twitter Account VISAV2.
Cheers,
Josh
Aug 4, 2015 at 12:01 PM
Happened again, as a different user so doesn't appear to be account specific.
Cheers,
Josh
Coordinator
Aug 4, 2015 at 12:19 PM
Hi again,

Please try to send me a user account for who you can reproduce it.
I just can't right now (I tried 'VISAV2').

I will continue trying.
Coordinator
Aug 4, 2015 at 12:38 PM
I have already tried on hundreds of users without encountering the issue once.
Can you repro it with any specific user or code?
Aug 4, 2015 at 1:04 PM
Hi Linvi,
It looks like it's trying to deserialise Rate Limit Exceeded messages as whatever the result would otherwise be (Tweets, Direct messages etc...).

I modified the latest version of TweetInvi so that JsonConvertWrapper.DeserializeObject catches the JsonSerializationException and creates a new Exception that also includes the raw JSON (basically the same as the patch I sent you the last time I had a problem with JSON Deserialization).
With this, the log messages now look like:
2015-08-04 12:57:35 - TwitterRestPoller.Program: Error: Exception whilst fetching User Home Feed. Exception:
JsonDeserializationException:
Tweetinvi.Core.Exceptions.DetailedJsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Tweetinvi.Core.Interfaces.DTO.ITweetDTO]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'errors', line 1, position 10.
   at Tweetinvi.Logic.Wrapper.JsonConvertWrapper.DeserializeObject[T](String json, JsonConverter[] converters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi.Logic\Wrapper\JsonConvertWrapper.cs:line 30
   at Tweetinvi.Logic.JsonConverters.JsonObjectConverter.DeserializeObject[T](String json, JsonConverter[] converters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi.Logic\JsonConverters\JsonObjectConverter.cs:line 26
   at Tweetinvi.Credentials.TwitterAccessor.ExecuteGETQuery[T](String query, JsonConverter[] converters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi.Credentials\TwitterAccessor.cs:line 139
   at Tweetinvi.Controllers.Timeline.TimelineQueryExecutor.GetHomeTimeline(IHomeTimelineParameters timelineParameters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi.Controllers\Timeline\TimelineQueryExecutor.cs:line 41
   at Tweetinvi.Controllers.Timeline.TimelineController.GetHomeTimeline(IHomeTimelineParameters parameters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi.Controllers\Timeline\TimelineController.cs:line 47
   at Tweetinvi.Timeline.GetHomeTimeline(IHomeTimelineParameters homeTimelineParameters) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\TweetInvi\Development - 0.9.9.x\Tweetinvi\Timeline.cs:line 76
   at TwitterRestPoller.Program.fetchUserHomeFeed(TwitterAccount user, Nullable`1 sinceId) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 621
   at TwitterRestPoller.Program.pollUserHomeFeed(TwitterAccount user) in c:\Users\Josh Keegan\Documents\Visual Studio 2013\Projects\CommsManager\TwitterRestPoller\Program.cs:line 585
Raw JSON:
{"errors":[{"message":"Rate limit exceeded","code":88}]}
Cheers,
Josh
Coordinator
Aug 4, 2015 at 1:08 PM
Thanks, I will have a look into this. I will get back to you in probably 2 hours.
Coordinator
Aug 4, 2015 at 3:34 PM
The issue has been resolved and was caused by a bad refactor from my side.
This will be released as part of version 0.9.9.2 probably this evening.

Thanks for the prompt feedback again.

Linvi
Coordinator
Aug 4, 2015 at 7:15 PM
This is now fixed. You can now download Tweetinvi 0.9.9.2.
Marked as answer by linvi on 8/4/2015 at 11:15 AM
Aug 5, 2015 at 11:24 AM
Thanks!