YamlDotNet
YamlDotNet copied to clipboard
deserializing a int[] failed
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?
When I removed the naming conventions your example worked, tests_config
properties was set to the values in the yaml file.
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.
I'm going to close this issue since you have figured out what the problem was. I'm glad you found it.