Skip to content

Incorrect serialization using fsi and Newtonsoft on dotnet 6.0.3xx #13493

Closed

Description

@JonCanning

Install dotnet 6.0.301 on Linux. I have tried Ubuntu and Debian on WSL.

sudo apt install dotnet-sdk-6.0

Run this script using dotnet fsi

#r "nuget:Newtonsoft.Json"

open Newtonsoft.Json

JsonConvert.SerializeObject {| x = 1 |}
|> printfn "%s"

or

type R = { x: int }
JsonConvert.SerializeObject { x = 1 } |> printfn "%s"

In either case output is

{"x@":1,"x":1}

Install 6.0.203

sudo apt install dotnet-sdk-6.0=6.0.203-1

output is

{"x":1}

Serialization is correct on Windows, and when using a regular class, only records in scripts are affected

Workaround

Use dotnet fsi --multiemit-

Activity

  1. changed the title [-]Incorrect serialization using Newtonsoft on dotnet 6.0.3xx[/-] [+]Incorrect serialization using fsi and Newtonsoft on dotnet 6.0.3xx[/+] on Jul 11, 2022
  2. dsyme commented on Jul 11, 2022

    @dsyme
    Contributor

    @JonCanning Thank you.

    As a workaround, using dotnet fsi --multiemit- makes the problem go away. You will lose debug symbols for scripts but that's all.

  3. dsyme commented on Jul 11, 2022

    @dsyme
    Contributor

    The problem is related to this line:

    ILMemberAccess.Public
    which is active for multi-assembly emit.

    There's a related line we need to check here: https://github.com/dotnet/fsharp/blob/main/src/Compiler/CodeGen/IlxGen.fs#L10675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions