OutOfMemoryException in CF Json.NET

Nov 23, 2009 at 10:22 AM

Hello,

Lately im fighting with an error that i get only in the CF edition of the library.

I use the serializer extensively with objects and files transferring them through TCP Sockets.

Everything works great on my desktop clients and server, but for my Windows Mobile clients,

when i send a file that is some big (but not really, cause this could happen and in a 600kb file),

i get an OutOfMemoryException while Deserializing the DataPackage object with the following StackTrace:

System.Collections.Generic.List`1.set_Capacity(Int32 value)
System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
System.Collections.Generic.List`1.Add(Object item)
Newtonsoft.Json.Utilities.CollectionWrapper`1.Add(Object item)
Newtonsoft.Json.Utilities.CollectionWrapper`1.System.Collections.IList.Add(Object value)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, String reference, JsonArrayContract contract)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.<>c__DisplayClass1.<CreateAndPopulateList>b__0(IList l, Boolean isTemporaryListReference)
Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType, Action`2 populateList)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, Object existingValue, String reference)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValue(JsonReader reader, Type objectType, Object existingValue, JsonConverter memberConverter)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonReader reader, Object target)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetObjectMember(JsonReader reader, Object target, JsonObjectContract contract, String memberName)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, Object existingValue)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValue(JsonReader reader, Type objectType, Object existingValue, JsonConverter memberConverter)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)
Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
Wizcom.InOrderII.Sockets.Mobile.WizcomTcpSocketClient.MessageArrivedHandler(Byte[] obj, State stateClient)
Wizcom.InOrderII.Sockets.Mobile.PacketProtocol.ReadCompleted(Int32 count, State stateClient)
Wizcom.InOrderII.Sockets.Mobile.PacketProtocol.DataReceived(Byte[] data, State stateClient)
Wizcom.InOrderII.Sockets.Mobile.WizcomTcpSocketClient.ReadCallBack(IAsyncResult ar)
System.Net.LazyAsyncResult.InvokeCallback(Boolean asyncCompletion)
System.Net.Sockets.Socket.WorkerThread.doWork()
System.Net.Sockets.Socket.WorkerThread.doWorkI(Object o)
System.Threading.ThreadPool.WorkItem.doWork(Object o)
System.Threading.Timer.ring()

 

The DataPackage object:

 

    public class DataPackage
    {
        public byte[] Data { get; set; }
        public CommandInOrder Command { get; set; }
        public byte[] Parameter { get; set; }
        public string ObjectType { get; set; }
        public int NumberOfFilesSplited { get; set; }
        public string OriginalFileName { get; set; }

        public DataPackage(byte[] data, CommandInOrder command, byte[] parameter, string objectType)
        {
            this.Data = data;
            this.Command = command;
            this.Parameter = parameter;
            this.ObjectType = objectType;
        }

        public DataPackage(byte[] data, CommandInOrder command, byte[] parameter, string objectType,
            int numberOfFiles, string originalFileName)
        {
            this.Data = data;
            this.Command = command;
            this.Parameter = parameter;
            this.ObjectType = objectType;
            this.NumberOfFilesSplited = numberOfFiles;
            this.OriginalFileName = originalFileName;
        }

        public DataPackage() { }
    }

Wish you could help with this major problem of mine..Thank you

 

 

Coordinator
Nov 24, 2009 at 4:37 AM

I don't know, my experience with CF is limited.

It could be you just have too much data for a mobile. 600kb is a lot of JSON.

Nov 26, 2009 at 9:08 PM

Fixed it with moving 512k of chunk files.