fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
226 stars 26 forks source link

When TrimMode is full, the deserialize error: "Required constructor is not defined." #70

Closed muqiuhan closed 4 months ago

muqiuhan commented 4 months ago

As the title says, when I enable PublishTrimmed and set TrimMode to full, the deserialize function reports the following error:

Unhandled Exception: System.ArgumentException: The record type 'Stoream.Engine.Config+Config' is invalid. Required constructor is not defined.
   at Microsoft.FSharp.Reflection.Impl.getRecordConstructorMethod(Type, BindingFlags) + 0x1ae
   at Microsoft.FSharp.Reflection.FSharpValue.MakeRecord(Type, Object[], FSharpOption`1) + 0x4f
   at FSharp.Json.Json.deserializeEx[T](JsonConfig, String) + 0x91
   at Stoream.Engine.Server.Server.Start() + 0x42
   at stoream-engine!<BaseAddress>+0x441579
[1]    13582 IOT instruction (core dumped)

Stoream.Engine.Config is defined as follows:

type AccountConfig = { Username: String; Password: String }
type ServerConfig = { Hostname: String; Port: UInt16 }
type StorageConfig = { Root: String; Capacity: UInt32 }

type Config =
    { Account: AccountConfig
      Server: ServerConfig
      Storage: StorageConfig }

    static member public CONFIG =
        IO.File.ReadAllText("./stoream-engine.json") |> Json.deserialize<Config>

When I set TrimMode to partial this error doesn't occur.