Exception: Could not cast or convert from System.Int64 to System.Int32

Sep 9, 2009 at 8:07 AM

Hi,

I'm using TweetShap (http://tweetsharp.com/) which is incorporating Newtonsoft.Json.dll . When deserializing a JSON string, I get the following error message / exception:

-        ex    {"Could not cast or convert from System.Int64 to System.Int32."}    System.Exception


        StackTrace    "   bei Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)\r\n   bei Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)\r\n   bei Newtonsoft.Json.JsonSerializer.EnsureType(Object value, Type targetType)\r\n   bei Newtonsoft.Json.JsonSerializer.CreateObject(JsonReader reader, Type objectType, Object existingValue, JsonConverter memberConverter)\r\n   bei Newtonsoft.Json.JsonSerializer.SetObjectMember(JsonReader reader, Object target, Type targetType, String memberName)\r\n   bei Newtonsoft.Json.JsonSerializer.PopulateObject(Object newObject, JsonReader reader, Type objectType)\r\n   bei Newtonsoft.Json.JsonSerializer.CreateAndPopulateObject(JsonReader reader, Type objectType)\r\n   bei Newtonsoft.Json.JsonSerializer.CreateObject(JsonReader reader, Type objectType, Object existingValue, JsonConverter memberConverter)\r\n   bei Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)\r\n   bei Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n   bei Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonConverter[] converters)\r\n   bei Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)\r\n   bei Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)\r\n   bei Dimebrain.TweetSharp.Extensions.TwitterExtensions.Deserialize[T](String json)\r\n   bei Dimebrain.TweetSharp.Extensions.TwitterExtensions.AsSearchResult(String json)\r\n   bei TwitterRouter.Form1.getTweets() in ....

Is this a problem in json.net or in TweetSharp?

Thanks for your help, regards, Christian

Coordinator
Sep 10, 2009 at 11:47 PM

I think I have fixed that issue in the past. TweetSharp maybe using an older version of Json.NET. I would talk to the TweetSharp people about having the latest version.

If it isn't fixed by using the latest version, what is the class you are deserializing too and what is the JSON?