I have a class which looks like this:
public class Item
{
public Guid Id { get; set; }
public Guid Parent { get; set; }
public string Name { get; set; }
}
If I serialize it:
var parentId = Guid.NewGuid();
var items = new List<Item>
{
new Item {Id = parentId, Parent = Guid.Empty, Name = "Parent"},
new Item {Id = Guid.NewGuid(), Parent = parentId, Name = "Child"}
};
var builder = new StringBuilder();
var serializer = new YamlDotNet.Serialization.Serializer();
using (var writer = new StringWriter(builder))
{
serializer.Serialize(writer, items);
}
Console.WriteLine(builder.ToString());
The output is:
- Id: 1c49bc54-d0e3-494e-8fd7-b9ffd8c1892a
Name: Parent
- Id: dd54864a-61f7-4d73-b89d-9bd4e4c2c8f4
Parent: *o0
Name: Child
There is a reference *o0
created which is the ID of the other class which is it's parent. But YamlDotnet does not define this reference, therefore when deserializing I get an error saying it's missing an anchor.
Is this a bug in the framework or is there anything I can do about it?