Dataset and System Out of Memory Exception Dataset and System Out of Memory Exception. My rant aside, I was reading about serialization of a dataset. Getting out of memory exception while serializing large data using NewtonSoft json serializer [Answered] RSS 3 replies Last post May 12, 2016 04:39 AM by Yohann Lu. Why do I get 'Out of Memory' exception when serializing objects? Archived Forums A-B > ASMX Web Services and XML Serialization. I get the 'Out of memory' exception when I set the initial capacity to over 425MB. Can you suggest any workarounds for this problem? Can someone please suggest me an alternative to handle the out of memory exception keeping in mind my scenario. C# exception lucene dataset out-of-memory. Posted:.NET Remoting and Runtime Serialization, out of memory exception in.NET Remoting v2.0 - TCP Channel Binary formatter Top for now I am trying to avoid using a dataset to pass the data.
I've got a DataSet
with about 250k Rows and 80 Columns causing StringBuilder
to throw an OutOfMemoryException (@System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)) when calling .GetXml() on my dataset.
As I read here (last paragraph) this can be overcome by using binary representation instead of xml, which sounds logical. So I set the RemotingFormat-property on my dataset to binary but the issue still occurs.
I had a closer look to the GetXml-implementation and there seems to be no distinction based on the RemotingFormat. Instead, I found out that GetXmlSchemaForRemoting considers RemotingFormat, but this method is internal so I can't call it from the outside. It is called by private SerializeDataSet which is called by public GetObjectData.GetObjectData itself seems to be for custom serialization.
How can I binary (de-)serialize my dataset? Or call at least GetXml without throwing exceptions? Did I overlook any dataset property?
MikroDel2 Answers
The link you provided in you question is from 2008.
There is some more new discussions:
and also from SO 2011.
The last one is about problem with DataAdapter
while reading 150K records, but the answer can be also interestin for you:
The first thing that I'd check is how many columns you are returning, and what their data types are.
and
...you are either returning way more fields than you need, or perhaps that some of the fields are very large strings or binary data. Try cutting down the select statement to only return the fields that are absolutely needed for the display.
If that doesn't work, you may need to move from a DataTable to a list of a custom data type (a class with the appropriate fields).
from the accepted answer
As you discovered there is no built in way to serialize datasets as binary.
The only way to serialize your dataset as binary data is to implement your own formatter.
start here http://msdn.microsoft.com/en-us/magazine/cc163911.aspx