-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anchor not found when referenced in double nested structure #399
Comments
Looking at your code, I would expect it to work. I'll take a look. Have you tried adding a new line at the end of the yml string ? Maybe there's an issue when parsing in that case. |
I've tried both adding an empty line as well as a new property at the bottom, but neither had any effect. |
Ok, thanks for the feedback. I'll look into this issue as soon as possible. |
I've checked this again, and the error happens because the public class AreaRecord
{
public string Name { get; set; }
public List<LevelRecord> Levels { get; set; } = new List<LevelRecord>();
public List<dynamic> Monsters { get: set; }
} |
This does indeed solve my anchor problem, but not in the way that I had hoped. I expected that area record would contain the full goblin instance in the monsters list. Rather, the dynamic monster object in the list contains two properties:
I've added an updated test below, but it fails at the indicated line. I don't know if I have incorrect assumptions about how it is supposed to work, but I can't even see an indication that the monster matches the goblin anchor. [Fact]
public void Test()
{
var yml = @"
name: Forest
monsters:
- monster: &goblin
name: Goblin
attackType: Piercing
levels:
- level:
name: Clearing
monster: *goblin
locations:
- location:
name: Location 1
description: A nice location
monster: *goblin";
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.WithNamingConvention(new CamelCaseNamingConvention())
.Build();
var areaRecord = deserializer.Deserialize<AreaRecord>(yml);
Assert.NotNull(areaRecord);
Assert.NotNull(areaRecord.Levels[0].Locations[0]["monster"]); // Fails here
Assert.Equal("Goblin", areaRecord.Levels[0].Locations[0]["monster"]["name"]);
}
public class AreaRecord
{
public string Name { get; set; }
public List<LevelRecord> Levels { get; set; } = new List<LevelRecord>();
public List<dynamic> Monsters { get; set; } = new List<dynamic>();
}
public class LevelRecord
{
public string Name { get; set; }
public List<dynamic> Locations { get; set; } = new List<dynamic>();
} If I use a concrete type public class LocationRecord
{
public string Name { get; set; }
public string Description { get; set; }
public dynamic Monster { get; set; }
} |
That's because you are using |
There seems to be a problem with the way anchors are resolved. I get the following exception when running the test shown below:
YamlDotNet.Core.AnchorNotFoundException: '(Line: 18, Col: 14, Idx: 264) - (Line: 18, Col: 21, Idx: 271): Anchor 'goblin' not found'
. If I remove the last line of the yaml definition, it does not throw any exception, which means that the two outermost anchors are resolved correctly. It seems that for some reason, the third level of nesting breaks the ability for the deserializer to resolve the anchor.The text was updated successfully, but these errors were encountered: