4
dataElementsList : TypesAndData.DataElement list

is a list of 50,000 records (actually many more but let's start small). I am trying to serialize to a JSON file:

let ser = Json.DataContractJsonSerializer(typeof<TypesAndData.DataElement list>) 
use ofs = File.OpenWrite(fileName)
let result = ser.WriteObject(ofs, dataElementsList)

and am getting the infamous StackOverflowException. to be precise:

An unhandled exception of type 'System.StackOverflowException' occurred in FSharp.Core.dll

any advice?

Benjol
  • 63,995
  • 54
  • 186
  • 268
akaphenom
  • 6,728
  • 10
  • 59
  • 109

1 Answers1

5

You should not try to serialize an F# list this way. Convert it to an array with List.toArray.

(I expect that the DataContract serializers see lists as nested 'first'/'rest' data structures, which means 50000 tree depth of Json/Xml, which is not what you want.)

Brian
  • 117,631
  • 17
  • 236
  • 300
  • Did the trick I for giggles I paried down the list to 10 elements and it looked as though it was persisting the "inner structure" of the list - which makes sense if I think about it; thank you – akaphenom Apr 28 '10 at 19:36