FSharp.Configuration icon indicating copy to clipboard operation
FSharp.Configuration copied to clipboard

Yaml type provider: Can't read a list of objects

Open Kurren123 opened this issue 3 years ago • 2 comments

My config.yaml:

Targets:
  - Target: 1 0 1 0
    NoSlots: 2
    
  - Target: -1 0 -1 -1
    NoSlots: 2


Tiles:
  - 1 0 0 0
  - 0 0 1 0
  - -1 0 0 0
  - 0 0 -1 -1

My code:

open FSharp.Configuration
type Config = YamlConfig<"config.yaml">
let config = Config()
printfn "Number of targets: %d" config.Targets.Count

Output: Number of targets: 1

Operating system: Windows Target framework: .net 6 Package version: 2.0.0

Any help to be able to parse the list of objects "Targets" would be much appreciated!

Kurren123 avatar Feb 28 '22 14:02 Kurren123

As a workaround, it works if you explicitly load the configuration file at runtime :

  open FSharp.Configuration
  type Config = YamlConfig<"config.yaml">
  let config = Config()
+ config.Load "config.yaml"
  printfn "Number of targets: %d" config.Targets.Count

MrLuje avatar Sep 04 '22 18:09 MrLuje

I think we can add a new test to check this scenario automatically.

If no one works on it before, I'm going to take a look later.

64J0 avatar Jul 03 '23 14:07 64J0