I'm trying to use Yamldotnet library to serialize a model with circular references. Which serializer settings or data class attributes should I use to achieve this? I want to be able to serialize and deserialize the models back, keeping references.
Sample model:
public class Book
{
public string Title { get; set; }
public List<Author> Authors { get; set; }
}
public class Author
{
public string Name { get; set; }
public List<Book> Books { get; set; }
}
Currently I can serialize the model correctly to yaml:
&o0 !Author
Name: name1
Books:
- !Book
Title: title1
Authors:
- *o0
, but deserialization throws an exception:
YamlDotNet.Core.AnchorNotFoundException: (Line: 7, Col: 5, Idx: 70) - (Line: 7, Col: 8, Idx: 73): Alias $o0 cannot precede anchor declaration