Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
323 stars 44 forks source link

`System.Reflection.TargetInvocationException` when serializing empty anonymous record #137

Closed peterhirn closed 1 year ago

peterhirn commented 1 year ago
#r "nuget: FSharp.SystemTextJson"

open System.Text.Json
open System.Text.Json.Serialization

let options = JsonSerializerOptions()
options.Converters.Add(JsonFSharpConverter())

JsonSerializer.Serialize({| x = {| |} |}, options)
System.Reflection.TargetInvocationException: Exception has been thrown by the target 
of an invocation.
 ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.    
   at System.Text.Json.Serialization.JsonRecordConverter`1..ctor(JsonSerializerOptions options, JsonFSharpOptions fsOptions) in /home/runner/work/FSharp.SystemTextJson/FSharp.SystemTextJson/src/FSharp.SystemTextJson/Record.fs:line 26
Tarmil commented 1 year ago

This is fixed in v1.0.7. Thanks for the report!