YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

deserializing a int[] failed

Open hoshinohikari opened this issue 2 years ago • 1 comments

This is what I do when I try to deserialize an int[]

public class config
{
    public string light_com { get; set; }
    public string screen_com { get; set; }
    public int[] exposureTimes1 { get; set; }
}

............

var yaml_config = @"
light_com: COM1
screen_com: COM4
exposureTimes1:
- 10
- 20
- 50
- 100
"
var deserializer = new DeserializerBuilder()
    .WithNamingConvention(UnderscoredNamingConvention.Instance)  // see height_in_inches in sample yml 
    .Build();
tests_config = deserializer.Deserialize<config>(yaml_config);

I've tried a lot of things, but it's still wrong when deserializing.

YamlException: Property 'exposureTimes1' not found on type 'Timing_test.config'.

Could you please tell me what is the correct grammar?

hoshinohikari avatar Aug 08 '22 11:08 hoshinohikari

When I removed the naming conventions your example worked, tests_config properties was set to the values in the yaml file.

EdwardCooke avatar Aug 10 '22 01:08 EdwardCooke

I found this to be a spelling problem, and deserialization went wrong when I used uppercase letters as the member names of class. I used two computers to compile the same program, and that happened. PS. The environment is .Net core 6 in windows, visual studio 17.3.0.

hoshinohikari avatar Aug 17 '22 02:08 hoshinohikari

I'm going to close this issue since you have figured out what the problem was. I'm glad you found it.

EdwardCooke avatar Sep 08 '22 18:09 EdwardCooke