1

I'm trying, what I think, a very simple operation but I can't wrap my head around the exception I'm getting. Basically it's a copy of the Samples.DeserializeObjectGraph example in YamlDotNet: https://dotnetfiddle.net/eImc2H

[System.Runtime.Serialization.SerializationException: Property 'continent_id' not found on type 'YamlDotNet.Samples.DeserializeObjectGraph+Country'.]

I have tried both renaming the property in country to continent_id and the YAML to continentID, but it's still giving the error. So it's not just that it ignores my YamlMember row, it doesn't seems to find the Country class or something.

If I remove the countries array in the continents is it being parsed just fine.

Can someone please explain what I'm doing wrong here?

Jon
  • 322
  • 1
  • 11
  • There is a typo `[YamlMember(Alias = "contient_id",` , but fixing it didn't fix the problem :( – Fildor Mar 03 '20 at 14:42
  • thanks @Fildor, fixed the typo. But like you said, doesn't solve the problem – Jon Mar 03 '20 at 14:46
  • 1
    Ok, so I managed to solve the problem: Since my YAML file is snake case should I use UnderscoredNamingConvention, but I really don't understand why it doesn't work the way it is. So, not answering my own question but hoping for someone with a bit more insight could explain why it's wrong. – Jon Mar 03 '20 at 16:58

1 Answers1

0

You have missed currency property in your country class. Add this to your country class.

[YamlMember(Alias = "currency", ApplyNamingConventions = false)]
public string currency { get; set; }

It works with your current implementation and return this answer.

Africa
     * Algeria
Asia
     * Afghanistan
Europe
     * Albania
     * Andorra
Buddhika Chathuranga
  • 1,334
  • 2
  • 13
  • 22