F # DataContractJsonSerializer StackOverflowException

dataElementsList : TypesAndData.DataElement list 

- A list of 50,000 entries (in fact, a lot more, but let them start small). I am trying to serialize a JSON file:

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

and I get the notorious StackOverflowException. to be precise:

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

any advice?

+4
source share
1 answer

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

(I expect DataContract serializers to see lists as nested data structures of 'first' / 'rest', which means 50,000 the depth of the Json / Xml tree, which you don't want.)

+5
source

Source: https://habr.com/ru/post/1308268/


All Articles