开发者

F# DataContractJsonSerializer StackOverflowException

开发者 https://www.devze.com 2022-12-28 06:44 出处:网络
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:
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开发者_如何学Python.dll

any advice?


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消