Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 43 forks source link

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

Closed peterhirn closed 2 years ago

peterhirn commented 2 years 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 2 years ago

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